我想從我的excel文件中刪除重複的行。我有以下代碼行。 運行代碼後,它會創建modified_excel.xls。不過,我打開此文件「不支持的文件格式」使用JExcel API從excel文件中刪除行
Workbook sourceDocument = Workbook.getWorkbook(new File("C:\\source.xls"));
WritableWorkbook writableTempSource = Workbook.createWorkbook(new File("C:\\excel\\modified_excel.xls"), sourceDocument);
WritableSheet sourceSheet = writableTempSource.getSheet(0);
String previousContent = "";
for (int i = 7; i < sourceSheet.getRows(); i++) {
String currentContent = sourceSheet.getCell(0, i).getContents();
if(!currentContent.equals(previousContent)){
sourceSheet.removeRow(i);
}
previousContent = currentContent;
}
writableTempSource.close();
sourceDocument.close();
你爲什麼不使用['apache.poi'(http://poi.apache.org/download.html)的Java API與Excel等辦公文檔的工具來工作? – Lion 2012-03-17 17:31:34