[英]write data into excel xls file using java
我將數據保存在表格中(我已經從文件中收集了它),我想使用 java 將其寫入 Excel xls 文件
我只分享主要的 class,因為它顯示了我如何將數據保存在表格中
public static void main(String args[]) throws FileNotFoundException {
SylkParser test = new SylkParser();
Reader reader = new FileReader("file.slk");
List<SylkRecord> parsed = test.parseRecords(reader);
SylkSheet sheet = new SylkSheet(parsed);
String[][] table = new String[47][8];
// print array in rectangular form
for (int i=1; i<47; i++) {
for (int j=1; j<8; j++) {
String data = new String();
if (sheet.getCell(i,j) == null) { data = ""; }
else if (sheet.getCell(i,j).valueStr instanceof String) {data = sheet.getCell(i,j).valueStr; }
else if (sheet.getCell(i,j).valueNumber instanceof Number) {data = sheet.getCell(i,j).valueNumber.toString();}
table[i][j]=data;//your value
System.out.println(table[i][j]);
}
}
}
You might try using a library like Apache POI https://poi.apache.org/ (see also https://poi.apache.org/components/spreadsheet/quick-guide.html ) to handle writing in the custom XLS format . 可以通過簡單的 XML 導出以 XML 的形式寫入 XLSX,盡管手動生成正確的 output 需要做很多工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.