gpt4 book ai didi

java - Excel 在写入时缺少一些值

转载 作者:太空宇宙 更新时间:2023-11-04 08:22:37 25 4
gpt4 key购买 nike

我是 Apache-poi 新手,使用的是 3.8 版本的 poi。在 Excel 中写入值时,我会检查列名称是否匹配,我将在该列中写入一些值并完成它,然后我将再次开始在标题上写入。问题是,如果写入三个列值,则仅添加或保存最后一列值,而前两个值不会保存在该列中。谁能告诉我出了什么问题。 (抱歉,如有错误,敬请谅解)

 Code:
int i = 0;
Row row = sheet.createRow(i);
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFillBackgroundColor(HSSFColor.LIGHT_ORANGE.index);
String validate_header = null;
while (iterator.hasNext()) {
if (eiterator.hasNext()) {
validate_header = eiterator.next();
}
Cell cell = row.createCell(i);
String col_heading = iterator.next();
cell.setCellValue(col_heading);
if(col_heading.equalsIgnoreCase("Assigned Date"))
{
Add_value(i, col_heading, row, sheet);
row=sheet.getRow(0);
cell=row.getCell(i);
}
else if(col_heading.startsWith("Review"))
{
int count=-1;
int n=Col_values.get("Defect Summary").size();
for (int j = 0; j < n; j++) {
row = sheet.createRow(count);
cell = row.createCell(i);
String s="External QC Defect ";
cell.setCellValue(s);
count++;

}
row=sheet.getRow(0);
cell=row.getCell(i);

}

sheet.autoSizeColumn(i);
i++;

}

private static Sheet Add_value(int k,String name,Row row, Sheet sheet) {

System.out.println("Inside the add method");


if(name.equalsIgnoreCase("Assigned Date")||name.equalsIgnoreCase("Reported Date") )
{
vector = Col_values.get("TargetDate");
int count = 1;

System.out.println("IF Size of the vector " + vector.size());
for (int j = 0; j < vector.size(); j++) {

row = sheet.createRow(count);
cell = row.createCell(k);
String s = (String) vector.get(j);
System.out.println(s);
cell.setCellValue(s);
count++;

}
}
else
{
vector = Col_values.get("Defect Summary");
int count = 1;
System.out.println("ELSE Size of the vector " + vector.size());
for (int j = 0; j < vector.size(); j++) {

row = sheet.createRow(count);
cell = row.createCell(k);
String s = (String) vector.get(j);
System.out.println(s);
cell.setCellValue(s);
count++;
}
}
return sheet;

}

'

你能告诉我出了什么问题吗?

最佳答案

看起来Add_value开始从顶部创建行。因此,在第二次调用时,旧行将被删除。

替换

         row = sheet.createRow(count);

         row = k == 0 ? sheet.createRow(count) : sheet.getRow(count);

关于java - Excel 在写入时缺少一些值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9237723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com