如何在java中填充arraylist的excel数据 [英] How to fill excel data from arraylist in java
本文介绍了如何在java中填充arraylist的excel数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
首先我有像1,2,3,4,5,6,7,8
这样的arraylist数据,点击按钮后它会将arraylist数据放到我的excel数据库中。 />
但是arylylist数据不会从A列开始,而是从excel中的F列开始
在此之前,我想使用excel是我的数据库来存储一些数据。这是我第一次使用excel作为我的数据库
First i have arraylist data like 1,2,3,4,5,6,7,8
after i click the button it will put the arraylist data to my excel database.
But the arraylist data wouldn''t start from column A but start from column F in the excel
Before that, i want to using excel to be my database to store some data. This is my first time i using excel for my database
推荐答案
您好,
这是一个示例基于apache POI。
Hello,
Here is a sample based on apache POI.
public void fillData(int[] intArr)
{
int startCell = 6; // Corrosponds to F
HSSFWorkbook workbook = null;
HSSFSheet sheet = null;
HSSFCell cell = null;
HSSFRow sheetRow = null;
workbook = new HSSFWorkbook();
sheet = workbook.createSheet("WorkSheet");
sheetRow = getRow(sheet, 0);
for (int val : intArr)
{
cell = sheetRow.createCell(startCell);
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(((Integer) value).doubleValue());
}
}
/**
* Helper method to retrieve the numbered row. If row does not exists then
* a new row is inserted and it's reference is returned.
* @param sheet The worksheet from which a row reference is sought.
* @param rowNum the row number
* @return the reference to the numbered row.
*/
protected final HSSFRow getRow(HSSFSheet sheet, int rowNum)
{
HSSFRow sheetRow = null ;
sheetRow = sheet.getRow(rowNum);
if (null == sheetRow)
sheetRow = sheet.createRow(rowNum);
return sheetRow;
}
更多信息可以在Apache POI网站上找到[ ^ ]。
问候,
More info can be found at Apache POI Site[^].
Regards,
这篇关于如何在java中填充arraylist的excel数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文