How to update excel metadata using java
I am trying to update excel metadata in java using apache POI. Input file is large containing 8K columns and 600 rows. I am using below code
OPCPackage pkg = OPCPackage.open(new File("path for input"));
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().setTitle("Test Title");
XSSFWorkbook wb = new XSSFWorkbook(pkg);
FileOutputStream fos = new FileOutputStream("path for output");
BufferedOutputStream bos = new BufferedOutputStream(fos);
wb.write(bos);
fos.close();
Above code is throwing me Out Of memory exception as below.
java.lang.OutOfMemoryError: Java heap space
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3414)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1272)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1259)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
at org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:227)
at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:219)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.parseSheet(XSSFWorkbook.java:452)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:417)
at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:184)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:286)
Could you please help to overcome this issue for updating excel properties ?
excel apache-poi
add a comment |
I am trying to update excel metadata in java using apache POI. Input file is large containing 8K columns and 600 rows. I am using below code
OPCPackage pkg = OPCPackage.open(new File("path for input"));
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().setTitle("Test Title");
XSSFWorkbook wb = new XSSFWorkbook(pkg);
FileOutputStream fos = new FileOutputStream("path for output");
BufferedOutputStream bos = new BufferedOutputStream(fos);
wb.write(bos);
fos.close();
Above code is throwing me Out Of memory exception as below.
java.lang.OutOfMemoryError: Java heap space
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3414)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1272)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1259)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
at org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:227)
at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:219)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.parseSheet(XSSFWorkbook.java:452)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:417)
at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:184)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:286)
Could you please help to overcome this issue for updating excel properties ?
excel apache-poi
1
If you just want to save the properties, why are you loading the workbook streams just to save? Why not save the OPC layer directly?
– Gagravarr
Nov 12 at 9:35
Thank you .. i invoked pkg.close() immediately after changing the title. It worked. Also removed code that loads the workbook streams.
– user5310214
Nov 12 at 11:40
add a comment |
I am trying to update excel metadata in java using apache POI. Input file is large containing 8K columns and 600 rows. I am using below code
OPCPackage pkg = OPCPackage.open(new File("path for input"));
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().setTitle("Test Title");
XSSFWorkbook wb = new XSSFWorkbook(pkg);
FileOutputStream fos = new FileOutputStream("path for output");
BufferedOutputStream bos = new BufferedOutputStream(fos);
wb.write(bos);
fos.close();
Above code is throwing me Out Of memory exception as below.
java.lang.OutOfMemoryError: Java heap space
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3414)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1272)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1259)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
at org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:227)
at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:219)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.parseSheet(XSSFWorkbook.java:452)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:417)
at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:184)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:286)
Could you please help to overcome this issue for updating excel properties ?
excel apache-poi
I am trying to update excel metadata in java using apache POI. Input file is large containing 8K columns and 600 rows. I am using below code
OPCPackage pkg = OPCPackage.open(new File("path for input"));
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().setTitle("Test Title");
XSSFWorkbook wb = new XSSFWorkbook(pkg);
FileOutputStream fos = new FileOutputStream("path for output");
BufferedOutputStream bos = new BufferedOutputStream(fos);
wb.write(bos);
fos.close();
Above code is throwing me Out Of memory exception as below.
java.lang.OutOfMemoryError: Java heap space
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3414)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1272)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1259)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
at org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:227)
at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:219)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.parseSheet(XSSFWorkbook.java:452)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:417)
at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:184)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:286)
Could you please help to overcome this issue for updating excel properties ?
excel apache-poi
excel apache-poi
asked Nov 12 at 7:50
user5310214
31
31
1
If you just want to save the properties, why are you loading the workbook streams just to save? Why not save the OPC layer directly?
– Gagravarr
Nov 12 at 9:35
Thank you .. i invoked pkg.close() immediately after changing the title. It worked. Also removed code that loads the workbook streams.
– user5310214
Nov 12 at 11:40
add a comment |
1
If you just want to save the properties, why are you loading the workbook streams just to save? Why not save the OPC layer directly?
– Gagravarr
Nov 12 at 9:35
Thank you .. i invoked pkg.close() immediately after changing the title. It worked. Also removed code that loads the workbook streams.
– user5310214
Nov 12 at 11:40
1
1
If you just want to save the properties, why are you loading the workbook streams just to save? Why not save the OPC layer directly?
– Gagravarr
Nov 12 at 9:35
If you just want to save the properties, why are you loading the workbook streams just to save? Why not save the OPC layer directly?
– Gagravarr
Nov 12 at 9:35
Thank you .. i invoked pkg.close() immediately after changing the title. It worked. Also removed code that loads the workbook streams.
– user5310214
Nov 12 at 11:40
Thank you .. i invoked pkg.close() immediately after changing the title. It worked. Also removed code that loads the workbook streams.
– user5310214
Nov 12 at 11:40
add a comment |
1 Answer
1
active
oldest
votes
Promoting a comment to an answer....
If you're just changing the OPC level metadata, there's no need to load the file up in the XSSF
layer at any point. You'd only need to do that if you also wanted to change the spreadsheet contents eg cells
Your code can be as simple as
OPCPackage pkg = OPCPackage.open(new File("path for input"));
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().setTitle("Test Title");
props.commit();
pkg.close();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257830%2fhow-to-update-excel-metadata-using-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Promoting a comment to an answer....
If you're just changing the OPC level metadata, there's no need to load the file up in the XSSF
layer at any point. You'd only need to do that if you also wanted to change the spreadsheet contents eg cells
Your code can be as simple as
OPCPackage pkg = OPCPackage.open(new File("path for input"));
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().setTitle("Test Title");
props.commit();
pkg.close();
add a comment |
Promoting a comment to an answer....
If you're just changing the OPC level metadata, there's no need to load the file up in the XSSF
layer at any point. You'd only need to do that if you also wanted to change the spreadsheet contents eg cells
Your code can be as simple as
OPCPackage pkg = OPCPackage.open(new File("path for input"));
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().setTitle("Test Title");
props.commit();
pkg.close();
add a comment |
Promoting a comment to an answer....
If you're just changing the OPC level metadata, there's no need to load the file up in the XSSF
layer at any point. You'd only need to do that if you also wanted to change the spreadsheet contents eg cells
Your code can be as simple as
OPCPackage pkg = OPCPackage.open(new File("path for input"));
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().setTitle("Test Title");
props.commit();
pkg.close();
Promoting a comment to an answer....
If you're just changing the OPC level metadata, there's no need to load the file up in the XSSF
layer at any point. You'd only need to do that if you also wanted to change the spreadsheet contents eg cells
Your code can be as simple as
OPCPackage pkg = OPCPackage.open(new File("path for input"));
POIXMLProperties props = new POIXMLProperties(pkg);
props.getCoreProperties().setTitle("Test Title");
props.commit();
pkg.close();
answered Nov 13 at 17:25
Gagravarr
36.7k875116
36.7k875116
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257830%2fhow-to-update-excel-metadata-using-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If you just want to save the properties, why are you loading the workbook streams just to save? Why not save the OPC layer directly?
– Gagravarr
Nov 12 at 9:35
Thank you .. i invoked pkg.close() immediately after changing the title. It worked. Also removed code that loads the workbook streams.
– user5310214
Nov 12 at 11:40