2 回答

TA貢獻1995條經(jīng)驗 獲得超2個贊
您可以借助APACHE POI將您的輸入寫入電子表格。
在這里查看 - https://www.tutorialspoint.com/apache_poi/apache_poi_spreadsheets.htm
簡而言之,該邏輯將幫助您將電子表格添加到現(xiàn)有的 excel 文件中。
HSSFWorkbook workbook = null; // creating a new workbook
File file = new File(context.getExternalFilesDir(null), "Sample.xls"); //getting a file with this name if not exist will create a new excel file with this in below steps
FileOutputStream fileOut = new FileOutputStream(file); // output stream is used to write to a file
if (file.exists()) { // if file exists add a new workbook to it
try {
workbook = (HSSFWorkbook)WorkbookFactory.create(file);
} catch (InvalidFormatException e) {
e.printStackTrace();
}
//add logic to convert the input to excel rows and write it into a wrokbook like this
HSSFSheet sheet = workbook.createSheet("Sample sheet2");
}
else{ // create a new workbook
workbook = new HSSFWorkbook();
// for the first time if nothing is there this will execute
//add logic to convert the input to excel rows and write it into a wrokbook like this
HSSFSheet sheet = workbook.createSheet("Sample sheet1");
}
workbook.write(fileOut); // closing the workbook after all operations
fileOut.close(); // closing the output stream
如果您對 JAVA 不太熟悉,這可能看起來有點復雜,但我建議您在此處提出任何不合理的問題。

TA貢獻1884條經(jīng)驗 獲得超4個贊
可以使用poi相關的依賴,就像這樣
WritableWorkbook book = Workbook.createWorkbook(new File("c:\\test.xls"));
WritableSheet sheet = book.createSheet("sheet1", 0);
Label label = new Label(0, 0, "test");
sheet.addCell(label);
jxl.write.Number number = new jxl.write.Number(1, 0, 555.12541);
sheet.addCell(number);
book.write();
book.close();
這個可以編輯windows excel,可以通過google了解poi相關操作。當然,我認為更好的方法是通過 javaEE 創(chuàng)建一個 Web 項目
添加回答
舉報