In my java application i am trying to create a Workbook from a template. Here is a code snippet to do that,
InputStream inStream=new FileInputStream(file);
Workbook workbook = new Workbook(inStream);
When the template is blank or contains plain text, it is converted to Workbook but when template contains png or other charts exception occurs as:
com.aspose.cells.CellsException: Invalid sectionId of Header Footer
image
Please Help!
We need your template file to evaluate your issue properly. Please post your issue with template Excel file in the Aspose.Cells forum there, we will check it soon.
I am working as Support developer/ Evangelist at Aspose.
Related
How to Write custom properties to a sheet in workbook using aspose - cells -7
CustomPropertyCollection custom = customProp.getCustomProperties();
Here's a code snippet to begin with
See the following sample code using Aspose.Cells for Java to accomplish the task for your reference:
e.g.
Sample code:
// Open an Excel file
Workbook workbook = new Workbook("Book1.xlsx");
// Retrieve a list of all custom document properties of the Excel file
CustomDocumentPropertyCollection customProperties = workbook.getWorksheets().getCustomDocumentProperties();
// Adding a custom document property to the Excel file
DocumentProperty publisher = customProperties.add("Publisher", "Aspose");
// Save the file
workbook.save("out1.xlsx", SaveFormat.XLSX);
PS. I am working as Support developer/ Evangelist at Aspose.
I would like to create a copy of word or excel file using poi.
I know that poi is also used when reading a word or excel file. Reading means not only values but also attribute such as font size or table color and backgroud colors for each cells. Reading values and attribute of the xlsx or docx document, I want to make a copy of the word or Excel document as it is. Is it possible that the related source is open at open source on the any site?
read Apache POI or docx4j for dealing with docx documents
you can find the techniques related to adding text into document you can found out on https://www.slideshare.net/plutext/document-generation-2012osdcsydney
use POI's HWPF support. this is often enclosed in docx4j as a dependency. however its not an excellent approach, since it does not convert the doc to docx4j's internal representation:- you are kind of stuck in HWPF land
use JODConverter to convert the doc to a docx, and if necessary, back again. this is often the simplest .
To open an excel from one file, and save it to another file I use this code.
//open source excel
InputStream template = new FileInputStream("C:\\source excel path\\input.xlsx");
Workbook wb = WorkbookFactory.create(template);
//Saving excel to a different location or filename.
FileOutputStream out = new FileOutputStream("C:\\path to copy excel to\\output.xlsx");
wb.write(out);
wb.close();
out.close();
template.close();
My requirements is to create an XSSFName using XSSFWorkbook.createName(). My code is :
Name name = myworkbook.createName();
...
myworkbook.write(fos);
But I get this error from excel when I open it :
Excel found unreadable content in 'filename.xlsm'. Do you want to reciver the contents of this workbook? If you trust the source of this workbook, click Yes.
I want to avoid this message.
I'm using org.apache.poi 3.14
My workbook is an instance of XSSFWorkbook, before I was using HSSFWorkbook and I did not have this problem. The implementation of createName is different from XSSF to HSSF.
There is other people having the same issue but with an old version
I currently create xls files by outputting an HTML table with the proper header and file extension. Here is the sample code:
String tabledata = "<table>MORE TABLE HTML HERE</table>";
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=\"somefile.xls\"");
out.println(tabledata);
This works great except you get an error before opening "The file format and extension of 'somefile.xls' don't match." Once opened, it looks exactly how I want it.
I used Apache POI elsewhere, so figured I could try using this, but I don't want to have to build all elements in some long script looking for rows, columns and different styles. I was thinking that I could convert the HTML to an InputStream and then create the Workbook, but it doesn't like the headers. Here is the code:
InputStream is = new ByteArrayInputStream(tabledata.getBytes("UTF-8"));
HSSFWorkbook wb = new HSSFWorkbook(is);
FileOutputStream fileOut = new FileOutputStream("somefile.xls");
wb.write(fileOut);
fileOut.close();
Is something like this possible if the headers were added/changed? If so, how would I modify this code to work properly?
I want to edit an existing Excel file with Java, to add some more data to an existing template excel file. So i used Jexcel for this purpose.
As suggested everywhere, I tried the following,
Workbook existingWorkbook = Workbook.getWorkbook(new File("H://"+file_name));
WritableWorkbook copy = Workbook.createWorkbook(new File("H://"+file_name+"_temp1.xls"));
But it shows an exception in the second line.
jxl.common.AssertionFailed
at jxl.common.Assert.verify(Assert.java:37)
at jxl.read.biff.SheetReader.handleObjectRecord(SheetReader.java:1811)
at jxl.read.biff.SheetReader.read(SheetReader.java:1059)
at jxl.read.biff.SheetImpl.readSheet(SheetImpl.java:716)
at jxl.read.biff.WorkbookParser.getSheet(WorkbookParser.java:257)
at jxl.write.biff.WritableWorkbookImpl.copyWorkbook(WritableWorkbookImpl.java:969)
at jxl.write.biff.WritableWorkbookImpl.<init>(WritableWorkbookImpl.java:343)
at jxl.Workbook.createWorkbook(Workbook.java:339)
at jxl.Workbook.createWorkbook(Workbook.java:320)
at run_book.process_input.<init>(process_input.java:83) <--create workbook stt.
.........<stack trace goes on>
So how could one edit an already existing jexcel file.
I did get another warning
Warning: Text Object on sheet "sheet2" not supported - omitting
Thanks in advance :)
Figured out the problem.
We have to close the input file before writing back (editing) the same file.
so to edit an existing Excel file with Jexcel
File inp = new File("H://"+file_name);
File out = new File("H://"+file_name);
Workbook existingWorkbook = Workbook.getWorkbook(inp);// This opens up a read-only copy of the workbook
WritableWorkbook copy = Workbook.createWorkbook(out,existingWorkbook); // This opens up a writable workbook so that we can edit the copy
//..........Some writes to excel workbook...........
// Now before writing & closing the copy, first close the existing one
existingWorkbook.close(); // Important: Close it before writing the copy with copy.write();
inp.close();
copy.write();
copy.close();
I ran into this same issue and to solve the problem I updated to the latest version of jxl.jar via maven. After doing this there was a very long delay when it ran destinationWorkbook = Workbook.createWorkbook(outputFile, sourceWorkbook); but it completed successfully without errors.