您好,我正在编写一个将.xls转换为.txt的程序。我的程序几乎可以完美运行。它可以很好地插入文本,但事实是它不能完全插入xls文件。它不会插入最后20行。我需要转换的xls包含1548行,其中1528行以我想要的格式正确插入。对我来说似乎很奇怪,只有20行没有插入。有任何想法吗?
public class create_text_doc {
public void writing() {
try {
File textgen = new File("C:\\Users\\darroyo\\Desktop\\expru.txt");
FileOutputStream fos = new FileOutputStream(textgen);
OutputStreamWriter osw = new OutputStreamWriter(fos);
Writer w = new BufferedWriter(osw);
String FilePath = "C:\\Users\\darroyo\\Desktop\\saldos_to_conv.xls";
FileInputStream fs = new FileInputStream(FilePath);
Workbook wb = Workbook.getWorkbook(fs);
Sheet hoja = wb.getSheet("Contratos");
int totalNoOfRows = hoja.getRows();
int totalNoOfCols = hoja.getColumns();
w.write("\n");
for (int row = 1; row < totalNoOfRows; row++) {
for (int col = 0; col < totalNoOfCols; col++) {
System.out.print(hoja.getCell(col,row).getContents() + "\t");
w.write("Deposito por Saldo Inicial|"+hoja.getCell(0,row).getContents()+"|EFECTIVO| | |0|0|0|0|0|0|0|"+hoja.getCell(1,row).getContents()+"|"+
new SimpleDateFormat("dd/MM/yyyy").format(Calendar.getInstance().getTime())+"|0|"+
new SimpleDateFormat("dd/MM/yyyy").format(Calendar.getInstance().getTime())+"|0|0|"+hoja.getCell(3,row).getContents()+"|"+
new SimpleDateFormat("dd/MM/yyyy").format(Calendar.getInstance().getTime())+"|0|0\n");
}
System.out.println();
}
} catch (IOException e) {
System.err.println("Problem writing txt file");
} catch (BiffException e) {
e.printStackTrace();
}
}
public static void main(String[]args) {
create_text_doc write = new create_text_doc();
write.writing();
}
}
我的for循环中的system.out.println正确打印出所有行,问题是当我将它们放入文本文档中时。我以为可能是问题所在,但删除它后,我仍然缺少20行。