How to update excel metadata using java










0














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 ?










share|improve this question

















  • 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















0














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 ?










share|improve this question

















  • 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













0












0








0







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 ?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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












  • 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












1 Answer
1






active

oldest

votes


















0














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();





share|improve this answer




















    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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();





    share|improve this answer

























      0














      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();





      share|improve this answer























        0












        0








        0






        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();





        share|improve this answer












        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();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 17:25









        Gagravarr

        36.7k875116




        36.7k875116



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto