Tag: fileoutputstream

XSSFSheet:图表索引超出范围

我正在写POI的xlsx文件的内容,但得到了一个IllegalArgumentException 。 以下是我的代码: public static void ConvertToCSVOrgtoOrg(String Scenario) throws Exception { String IntermediateXLSXPath=GetFileDetailsSIF(Scenario,"ExcelPath"); String IntermediateCSVPath=GetFileDetailsSIF(Scenario,"CSVPathOrgtoOrg"); File inputFile = new File(IntermediateXLSXPath); File outputFile = new File(IntermediateCSVPath); // For storing data into CSV files StringBuffer data = new StringBuffer(); try { FileOutputStream fos = new FileOutputStream(outputFile); // Get the workbook object for XLSX file XSSFWorkbook wBook = […]

使用StreamingOutput对象写入excel文件。 (java.lang.ClassCastException)

我有一个返回StreamingOutput对象的方法。 而我想把这个StreamingOutput对象写入excel文件。 而且我写了下面的代码,它给了我java.lang.ClassCastExceptionexception。 StreamingOutput stream = getStreamObject(); SXSSFWorkbook workBook = (SXSSFWorkbook) stream; //Exception occurs here FileOutputStream fileOut = new FileOutputStream("/save/excel/file/here"); workBook.write(fileOut); fileOut.flush(); fileOut.close(); 所以,请帮我解决这个问题。 先谢谢你。

如果Excel文件处于打开状态,Excel文件不能被Java-Program访问

我的代码应该打印一个数字(在这种情况下数字5)到指定的Excel工作簿中指定的单元格。 如果Excel-Workbookclosures,代码将起作用。 但是,如果Excel-Workbook打开,运行代码时出现以下错误消息: Exception in thread "main" java.io.FileNotFoundException: C:\Users\Username\Desktop\java-Programs\test.xlsm (The process can't access the file because it is used by another process) 代码如下: XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(new File("C:\\Users\\Username\\Desktop\\java-Programs\\test.xlsm"))); XSSFSheet ExcelSheet = wb.getSheet("Output"); XSSFRow row = ExcelSheet.getRow(3); XSSFCell cell = row.getCell(0); cell.setCellValue(5); FileOutputStream fileOut = new FileOutputStream("C:\\Users\\Username\\Desktop\\java-Programs\\test.xlsm"); wb.write(fileOut); fileOut.close(); 我想在运行java代码时保持文件打开。 有人知道我必须改变,以便能够保持运行代码时打开Excel文件?

制作一个Excel可读文件?

有没有关于能够使用toString或单独的方法来写入文件的信息,该文件实际上可以在Excel中使用和打开,从而创buildExcel单元格等? 或者这不是一个众所周知的做法。

FileOutputStream(Apachhe POI)花费太长的时间来保存

当我使用Apache poi编辑.xlsx文件时,需要很长时间才能保存。 .xlsx文件包含公式格式化和冻结窗格。 我正在使用下面的代码, try { FileInputStream file = new FileInputStream(new File(path)); XSSFWorkbook fWorkbook = new XSSFWorkbook(file); XSSFSheet fSheet = fWorkbook.getSheetAt(0); for(int i = 0; i < jTable1.getRowCount(); i++){ if(jTable1.getModel().getValueAt(i, index1).equals("1")){ XSSFCell cell = fSheet.getRow(i+1).getCell(index1); cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(new Double(1)); XSSFCellStyle cs = fWorkbook.createCellStyle(); cs.setDataFormat(fWorkbook.getCreationHelper().createDataFormat().getFormat("dd/MMMM/yyyy")); cell =fSheet.getRow(i+1).getCell(index2); cell.setCellValue(new Date()); cell.setCellStyle(cs); } } file.close(); FileOutputStream fileOutputStream = new […]