We use Apache POI 3.14 to generate a pptx document from Sling content, using the bundle org.apache.servicemix.bundles.poi.
In a simple standalone Java app, with test code, it works fine.
When we put this code in a bundle and deploy it to Felix, the generated table consists of a single empty cell.
I found a few posts describing a similar problem, some asking to replace poi-ooxml-schemas with ooxml-schemas, but I'm wondering if it would fix our issue as the standalone app works with the same POI bundle than the one deployed to Felix.
This is the code we use:
public static void addTableToSlide(XMLSlideShow ppt, XSLFSlide slide) {
XSLFTable tbl = slide.createTable(1, 1);
for (int i = 0; i < 9; i++) {
XSLFTableRow row = tbl.addRow();
for (int j = 0; j < 9; j++) {
row.addCell();
}
}
tbl.setAnchor(new Rectangle2D.Double(50, 50, 450, 300));
}
And this is what is generated in Felix:
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">
<a:tbl>
<a:tblPr/>
<a:tblGrid/>
</a:tbl>
</a:graphicData>
What could cause this issue, could it be a conflict between libraries? How could I debug it to find what is wrong in Felix?
This is a classloading issue and a workaround will be available in POI 3.16 - see Bugzilla entry #60226
Furthermore you might want to check #57857 for a servicemix patch.
Related
This code works well in Excel online but not works in Excel desktop. In Excel Desktop it generate error in browser log :
"This operation is not permitted for the current object." on the line "chart.legend.legendEntries.getItemAt(i).visible".
Here the sample of the code where the problem occurs :
// Create an chart.
chart = activeSheet.charts.add(chartType, chartRange, 'Auto');
...
// Add a serie
for (let i = 0; i < nbSeries; ++i) {
const newSeries = chart.series.add(legend);
}
...
// Set legend visibility
for (let i = 0; i < nbSeries; i += 1) {
chart.legend.legendEntries.getItemAt(i).visible = false;
}
The legendEntry is available since ExcelApi 1.7.
My Excel is an version 1912.
Thank you for you help !
When you want to hide the legend, you could use chart.legend.visible = false;.
The difference between Excel desktop and Excel online is that for Excel desktop, the new created chart doesn't include Legend, which included by default for Excel online.
If we try to get chart.legend.legendEntries when there's no Legend in Chart, we will get this error message.
i had a excel sheet which is coming to a jsp from the servlet. Can someone help me of how to write a jsp page to display the excel contents in the browser.
Thanks in advance.
If the excel is not changing the structure dynamically, I recommend you to build a set of objects and parse these information in the server, and then in the jsp read these objects to build an html table with this set of objects.
You can load an Excel file with the class HSSFWorkbook or XSSFWorkbook, and then loop to the rows and cells for building your objects.
Please have a look at the examples of Apache Poi here
You can do something like this...
if(sheet.getPhysicalNumberOfRows() > 0) {
lastRowNum = sheet.getLastRowNum();
for(int j = 0; j <= lastRowNum; j++) {
row = sheet.getRow(j);
lastCellNum = row.getLastCellNum();
for(int i = 0; i <= lastCellNum; i++) {
cell = row.getCell(i);
if(cell == null) {
csvLine.add("");
}
else { //set your properties here...
}
}
}
}
I have a very simple ExtendScript script which creates a new document out of a subset of the current active document:
var sourceDocument = app.activeDocument;
var i, j;
for(i = 0; i < sourceDocument.layers.length; i++) {
sourceDocument.layers.item(i).locked = false;
}
for(i = 0; i < sourceDocument.spreads.length; i++) {
for(j = 0; j < sourceDocument.spreads.item(i).textFrames.length; j++) {
if(sourceDocument.spreads.item(i).textFrames.item(j).locked) {
sourceDocument.spreads.item(i).textFrames.item(j).locked = false;
}
}
}
var destDocument = app.documents.add();
var firstPageIndex = 0; // In the actual script, this is chosen by the user.
var lastPageIndex = 5; // In the actual script, this is chosen by the user.
destDocument.importStyles(ImportFormat.paragraphStylesFormat, new File(sourceDocument.filePath + "/" + sourceDocument.name), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
destDocument.importStyles(ImportFormat.characterStylesFormat, new File(sourceDocument.filePath + "/" + sourceDocument.name), GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
destDocument.viewPreferences.horizontalMeasurementUnits = sourceDocument.viewPreferences.horizontalMeasurementUnits;
destDocument.viewPreferences.verticalMeasurementUnits = sourceDocument.viewPreferences.verticalMeasurementUnits;
destDocument.documentPreferences.facingPages = sourceDocument.documentPreferences.facingPages;
destDocument.documentPreferences.pageHeight = sourceDocument.documentPreferences.pageHeight;
destDocument.documentPreferences.pageWidth = sourceDocument.documentPreferences.pageWidth;
destDocument.documentPreferences.pageSize = sourceDocument.documentPreferences.pageSize;
destDocument.documentPreferences.allowPageShuffle = true;
var range = sourceDocument.pages.itemByRange(firstPageIndex, lastPageIndex);
range.duplicate(LocationOptions.AFTER, destDocument.pages[destDocument.pages.length - 1]);
destDocument.pages[0].remove(); // An empty spread containing an empty page is added when the new document is created and we cannot remove it before other pages are inserted (Documents must have at least one page)
This script works perfectly on many documents. But when I execute it against one particular document (let's call it foo.indd), InDesign becomes unresponsive when executing the duplication: range.duplicate(LocationOptions.AFTER, destDocument.pages[destDocument.pages.length - 1]);. From then on, the only thing I can do is force InDesign to quit.
Is this an InDesign bug? How can I find which part of this particular document is creating the problem?
I can't really say what's wrong in your example but if indesign hangs, that might caused by the loops ( to infinity and beyond :) )
So you may try to avoid issues by outputting the loop limit to avoid InDesign re-calculation
var limit = …
for ( i = 0; i<limit ; i++)…
Additionally you could try to write info on the console to get info where InDesign is actually being stuck. So write informations on the fly on a report file and you might finally identify the issue area.
Also, you can try to interrogate every key items to see if the file has some issue.
Last but not least, try a manual export to idml of this file, re open and run again the script. Sometimes files become clunky and passing by idml fix most of them.
Give this script a try onto your probleamtic file. If it fails, please have a look at the report it should have generated onto the desktop.
http://www.loicaigon.com/downloads/cloneDocument.jsx
Loic
http://www.loicaigon.com
I am writing an Excel File using Apache POI.
I want to write in it all the data of myResultSet
which has the fieldnames(columns) stored in the String[] fieldnames.
I have 70000 rows and 27 columns
My Code:
String xlsFilename = "myXLSX.xlsx";
org.apache.poi.ss.usermodel.Workbook myWorkbook = new XSSFWorkbook();
org.apache.poi.ss.usermodel.Sheet mySheet = myWorkbook.createSheet("myXLSX");
Row currentRow = mySheet.createRow(0);
for (int k = 0; k < fieldNames.length; k++) {
// Add Cells Of Title Of ResultsTable In Excel File
currentRow.createCell(k).setCellValue(fieldNames[k]);
}
for (int j = 0; j < countOfResultSetRows; j++) {
myResultSet.next();
currentRow = mySheet.createRow(j + 1);
for (int k = 0; k < fieldNames.length; k++) {
currentRow.createCell(k).setCellValue(myResultSet.getString(fieldNames[k]));
System.out.println("Processing Row " + j);
}
}
FileOutputStream myFileOutputStream = new FileOutputStream(xlsFilename);
myWorkbook.write(myFileOutputStream);
myFileOutputStream.close();
My problem is that while writing the rows the program is getting slower and slower.
When it reaches row 3500 it stops with the Exception:
Exception in thread "Thread-3" java.lang.OutOfMemoryError: Java heap space
at java.lang.AbstractStringBuilder.(AbstractStringBuilder.java:45)
at java.lang.StringBuffer.(StringBuffer.java:79)
It seems I'm out of memory.
How can I solve this.
Is there a way to store my data to a temporary file every 1000 of them (for example)?
What would you suggest?
I had the same problem using jxl and never solve it either (JAVA - Out Of Memory Error while writing Excel Cells in jxl)
Now I need xlsx files anyway, so I have to use POI.
There seems to be an approach which creates data file in XML format first and then replacing that XML with existing template xlsx file.
http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java
this is not applicable for xls format files though.
How about allowing your app to use more memory (like -Xmx500m for 500 MB)?
Assign more memory to the heap when running your program:
$ java -Xms256m -Xmx1024m NameOfYourClass
I've been there more than once.
Are you running this running on top of an application server?
What I've done in the past as was mentioned by Pablo, is to increase the heap space, but make sure that it is being increased for the application server that you are running on.
I have also had to really optimize the code when doing this.
Since you are outputting to a .xlsx file, XML takes quite a bit of memory. Not sure if it would work for you in this situation or not, but if you can create a normal .xls do that and than convert it at the end into a .xlsx file (using Apache POI of course).
Use SXSSFWorkbook instead of XSSFWorkbook, this is used for streaming User model Api
Source: https://coderanch.com/t/612234/Write-Huge-Excel-file-Xlsx
Hopefully this will help you.
I am look for a server side PDF library (or command line tool) which can:
split a multi-page PDF file into individual PDF files, based on
a search result of the PDF file content
Examples:
Search "Page ???" pattern in text and split the big PDF into 001.pdf, 002,pdf, ... ???.pdf
A server program will scan the PDF, look for the search pattern, save the page(s) which match the patten, and save the file in the disk.
It will be nice with integration with PHP / Ruby. Command line tool is also acceptable. It will be a server side (linux or win32) batch processing tool. GUI/login is not supported. i18n support will be nice but no required. Thanks~
My company, Atalasoft, has just released some PDF manipulation tools that run on .NET. There is a text extract class that you can use to find the text and determine how you will split your document and a very high level document class that makes the splitting trivial. Suppose you have a Stream to your source PDF and an increasingly ordered List that describes the starting page of each split, then the code to generate your split files looks like this:
public void SplitPdf(Stream stm, List<int> pageStarts, string outputDirectory)
{
PdfDocument mainDoc = new PdfDocument(stm);
int lastPage = mainDoc.Pages.Count - 1;
for (int i=0; i < pageStarts.Count; i++) {
int startPage = pageStarts[i];
int endPage= (i < pageStarts.Count - 1) ?
pageStarts[i + 1] - 1 :
lastPage;
if (startPage > endPage) throw new ArgumentException("list is not ordered properly", "pageStarts");
PdfDocument splitDoc = new PdfDocument();
for (j = startPage; j <= endPage; j++)
splitDoc.Pages.Add(mainDoc.Pages[j];
string outputPath = Path.Combine(outputDirectory,
string.Format("{0:D3}.pdf", i + 1));
splitDoc.Save(outputPath);
}
if you generalize this into a page range struct:
public struct PageRange {
public int StartPage;
public int EndPage;
}
where StartPage and EndPage inclusively describe a range of pages, then the code is simpler:
public void SplitPdf(Stream stm, List<PageRange> ranges, string outputDirectory)
{
PdfDocument mainDoc = new PdfDocument(stm);
int outputDocCount = 1;
foreach (PageRange range in ranges) {
int startPage = Math.Min(range.StartPage, range.EndPage); // assume not in order
int endPage = Math.Max(range.StartPage, range.EndPage);
PdfDocument splitDoc = new PdfDocument();
for (int i=startPage; i <= endPage; i++)
splitDoc.Pages.Add(mainDoc.Pages[i]);
string outputPath = Path.Combine(outputDirectory,
string.Format("{0:D3}.pdf", outputDocCount));
splitDoc.Save(outputPath);
outputDocCount++;
}
}
PDFBox is a Java library but it does have some command line tools as well:
http://pdfbox.apache.org/
PDFBox can extract text and also rebuilt/split PDFS
pdfminer + multi-line pattern matching in python
You can use pdfsam to split your file in pages, then use pdftotext (from foolabs.com) to turn this into text and use ruby (or grep) to find the strings. Then you have the page ranges and can return the previous generated pages.