When using jxl.write do Excel data export, format error: Maximum number of format records exceeded Using default format.

  I do not want to look at the analysis, looking directly at the final summary.

  The exported data needs, required for the formatting process, if the type of digital data, formatting is required. code show as below:

  But the resulting effect is not satisfactory, see the figure Excel Screenshot, sensitive information is not intercepted:

 

  Then look at the console newspaper warned:

  Warning:  Maximum number of format records exceeded.  Using default format.

  Baidu to point to a fundamental way, that is jxl change the source code, modify the maximum, the link is: https://blog.csdn.net/Dracotianlong/article/details/8928434  (PS: Baidu to all this, not who knows who copied ...)

However, this solution is extremely bad for ongoing maintenance, modification of the third-party source code ah. . .

  Later no recourse but to go stackoverflow find the answer, the answer did not find, to find a reason for this: the reference as follows: https://stackoverflow.com/questions/4182782/jxl-and-maximum-number-of-formatted- cells

Translation summarized as follows:

How do you create CellFormatan object?

You have to do is make sure that you are reusing CellFormatan object, rather than re-create them in the loop somewhere in.

Unless you really have 350 cells, each cell has a different format. Otherwise, create an CellFormatobject and pass it to thesetCellFormat

Viewed from above, we can see that we are constantly re-create a newCellFormat对象,超过了jxl的最大值,回过头再看代码,发现确实有个for循环,重复创建。

如图,有一个循环,肯定超过100的,所以有警告。(ps:图片的代码是已经修改好了的)

 

  总结:产生该警告的原因是因为,重复创建CellFormat的对象,超过了jxl设定的最大值100,所以这里我们要看我们的单元格是不是每一个都需要一个特定的格式,如果不需要则可以重复使用,创建的第一个对象,而不是重复创建。当然你本来想重复使用第一个CellFormat对象,但是一不小心重复创建了,那就要看是不是代码错误,跟我一样犯错了,将创建格式的代码放在了for循环中。

 

Guess you like

Origin www.cnblogs.com/timeout/p/11988376.html