Tag: apache poi

声纳空指针违规

声纳低于行下面的空指针违规 existed.keySet() 请你能帮我们解决这个问题。 private boolean isEqualCaptions(Map<String, String> existed, Map<String, String> updated) { if(existed == null && updated != null) return false; if(existed != null && updated == null) return false; for(String key:existed.keySet()){ if(existed.get(key).compareTo(updated.get(key)) != 0) return false; } return true; }

NPOI / POI Excel库ISheet.ShiftRows索引超出范围例外

我正在使用NPOI中的.ShiftRows插入一个新的行到一个Excel文件。 但是,当试图向下移动行以插入新行时,我在某些文件上收到System.ArgumentOutOfRangeException 。 这些只是我填充的不同公司的通用文件,因此它们可能不是“干净的”,即底部的空白行等等。我希望它仍然可以运行,因为NPOI知道最后一行在哪里。 在这种情况下,我将行16到458向下移动,得到了超出范围的exception。 例外: Server Error in '/' Application. Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and […]

如何设置公式在Apache POI中有表列字段

我使用下面的示例代码创build了一个XSSFTable: https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java 我的XSSFTable中的一列是引用此表中另一列的公式。 例如,在XSSFTable TBL列ColumnA ,公式为: =[@[ColumnB]] ,我可以通过cell.setCellFormula("TBL[[#This Row],[ColumnB]]")在ColumnA每个单元格上设置公式。 cell.setCellFormula("TBL[[#This Row],[ColumnB]]") ,但在Excel中打开时会出现问题,Excel必须删除公式才能正确显示工作表。 这个问题只发生在创build空白的新XSSFWorkbook时,如果它是从Excel创build的现有.xlsx文件加载的,则可以通过cell.setCellFormula()修改公式并能够在Excel中正确打开。 如果有什么样的代码可以在这种情况下正常工作?

用Apache-POI编写工作簿后发出问题

将数据插入带有.xlsm扩展名的Excel模板的表格后,出现问题。 代码工作。 它正确地复制有问题的数据,但是当我尝试运行一个特定的macros,它采用导入的数据,它不能识别所有行,只有前两个。 但是,如果我复制并粘贴第二列中的任何单元格,例如,如果我复制B2中的B2并执行macros,它将识别插入行的总数。 你可以帮我吗? 我希望我清楚。 这是我的function代码 public String generarExcelSalida(String codCampaña,JDateChooser fechaParametro,String tfOutFolder){ String fileName="Modelo Caida "+codCampaña+".xlsm"; String exitFilePath=tfOutFolder+"\\"+fileName; FileInputStream fileIn=null; FileOutputStream fileOut=null; SimpleDateFormat dParam=new SimpleDateFormat("dd/MM/yyyy"); String dateParam = dParam.format(fechaParametro.getDate()).toString(); ResultSet rs=DBManager.ConsultaCaida(dateParam, codCampaña); try { // Here I'm opening my template file fileIn=new FileInputStream(FileManagement.carpetaTemplate+"\\Template_Caidas.xlsm"); XSSFWorkbook workbook=new XSSFWorkbook(OPCPackage.open(fileIn)); XSSFSheet sheet9=workbook.getSheet("BASE_DATOS"); int i=1; // This parameter is […]

在excel中使用apache poi在java中合并文本中心

我已经创build了一个Excel工作表,我将值插入单元格并同时垂直合并单元格,我能够实现这一点,但问题是,我无法在合并的单元格中垂直居中alignment文本。目前,文本显示在垂直合并单元格的底部。 这是我的代码, CellStyle cs = null; cs = wb.createCellStyle(); cs.setWrapText(true); //cs.setAlignment(CellStyle.ALIGN_CENTER); cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cs.setFont(f); Row row[]=new Row[pageListAcrToDept.size()]; for (int i = 0; i < pageListAcrToDept.size(); i++) { rowIndex = 8 + i ; row[i]=sheet.createRow(rowIndex); } List<List<String>> datas=new ArrayList<>(); datas.add(pageListAcrToDept); datas.add(notesListAcrToDept); datas.add(treatmentListAcrToDept); datas.add(upcListAcrToDept); datas.add(itemCodeListAcrToDept); datas.add(descListAcrToDept); datas.add(subDeptListAcrToDept); datas.add(limitListAcrToDept); datas.add(XforListAcrToDept); datas.add(priceListAcrToDept); datas.add(couponListAcrToDept); datas.add(adzoneListAcrToDept); datas.add(promoDescListAcrToDept); for (int column = 0; […]

如何在使用兴趣点的Excel中获得列的最大长度

我正在研究一个涉及使用Apache POI读取excel数据的项目。 我有一个情况,我必须找出列的最大长度。 例如 一张纸有3行r1,r2,r3和2列c1和c2,全部包含string数据。 现在说r1c1的string大小是5,r2c1是6,r3c1是7。 Apache POI中是否有可用的方法 foo(c1)将返回7。 目前我正在使用foo循环遍历列中的所有单元格并计算最大大小,但是由于excel文件很大,所以它的性能很高。 我经历了文档,但找不到一个。 只有循环才能做到这一点? 为什么我要这个 我必须编写一个应用程序可以在数据库中上传excel的function。 应该立即创buildDDL语句并生成ddl语句,我需要知道列的最大长度。 我知道我正在尝试重新发明轮子,因为像MySQL这样的db已经有了这个插件,但是在这里,我不想使用它,因为我想把所有东西放在一个地方。 我浏览了插件的源代码,但在项目中复制太复杂了。

excel中的数值单元格值会在小数点后附加额外数字的情况下exception读取

请在下面的代码片段find。 该实现读取excel表格中特定列的单元格值。 数字值(如459000.00)正在被代码读取为459000.00000000006。 对于less数人来说,这是工作得很好,但是对一些人来说却是失败的。 try { String AmountColumn="C"; File FS = new File(FileLocation); FileInputStream FileStream = new FileInputStream(FS); XSSFWorkbook FileWorkbook = new XSSFWorkbook(FileStream); Sheet FileWorksheet = FileWorkbook.getSheetAt(0); double[] AmountArray = new double[FileWorksheet.getPhysicalNumberOfRows() – 1]; Iterator<Row> iterator2 = FileWorksheet.iterator(); int i2 = 0; while (iterator2.hasNext()) { if (i2 == 0) { iterator2.next(); } else { AmountArray[i2 […]

使用java在Excel表格中创build数据透视表

如何使用java在透视表中设置标题标题。 我必须在Excel表中使用Apache poi创build数据透视表。现在使用java更改行和列标题标签。

JAVA Excel文件被损坏

我尝试在包含第一个我添加的文件中写第二个表。 没有重叠的行,文件被损坏,但它插入的表,格式化在excel formatAsTable风格一切正常。 我怎样才能消除这个问题? 我不能有一个损坏的文件,即使数据都很好。 public class formatAsTable2 { public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException { String[][] multi = new String[][]{ { "Advisor", "notContacted", "appointmentsUTD", "totalWorkLoad", "notResponsiveCalls", "successfulCalls", "totalCalls", "totalIncomingEmails", "totalCommunication", "emailsSent","offerLetters","appFees","deposits" }, { "Sharon Brown", "42", "44", "86", "62", "27", "89", "21", "220", "131" , "0", "6", "2", "0"}, { "Elena […]

JAVA APACHE-POI表

有这个下面的类,这将成为一个循环的一部分,这将在Excel表中添加很多表。 我的问题是,我无法弄清楚,如何使格式为formatAsTable风格的表格计算总计行中的值。 我把这2行代码: cttable.setTotalsRowShown(true); cttable.setTotalsRowCount(1); 把filter,但公式是不存在的。我知道我有string值,将改变那些后来,但这些都不是问题。下面的完整代码,如果有人知道如何,请详细说明,因为我不知道如何。 import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Random; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.util.AreaReference; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFTable; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo; public […]