That's interesting information, but the solution I described works.  I
can hold the initial empty xlsx in memory, then write out the full
document to any output stream.

Here's what it looks like (in groovy).  permOut could be any output
stream, wb is a workbook loaded with the styles needed, sheet is the
sheet that will be replaced with a large xml doc.


        def permOut = new FileOutputStream("target/ooxml.xlsx")
        ZipOutputStream zipOut = new ZipOutputStream(permOut)


        ByteArrayOutputStream tempOut = new ByteArrayOutputStream()
        wb.write(tempOut)

        ZipInputStream zipIn = new ZipInputStream(new
ByteArrayInputStream(tempOut.toByteArray()))
        ZipEntry entry = zipIn.nextEntry

        String sheetName = sheet.packagePart.partName.name.substring(1)
        while (entry != null) {
            if (!entry.name.equals(sheetName)) {
                zipOut.putNextEntry(new ZipEntry(entry.name))
                copyStream(zipIn, zipOut)
                zipOut.closeEntry()
            }
            entry = zipIn.nextEntry
        }

        zipOut.putNextEntry(new ZipEntry(sheetName))

        // write large sheet xml

        zipOut.closeEntry()
        zipOut.close()



On Wed, Oct 20, 2010 at 10:04 AM, Mark Beardsley
<[email protected]> wrote:
>
> How complex is the formatting? If you open a blank excel document, set the
> widths of columns and apply formatting to them then import a CSV file into
> this document, the formatting rules will be applied to the data as the sheet
> is populated. This will only work for simple formatting of course, if you
> need to have, for example, a totals row at the end of the document and the
> values for this row must be calculatyed from the data you are reading in
> then this presents more of a problem.
>
> You might want to look at using an Excel macro to open the CSV file and
> populate the workbook. A macro would be able to ocate a file on your
> machine, to open it, read the data and populate the workbook; indeed, macros
> can do anything you - a user - could. Further, this macro can be set to run
> when the user opens the workbook and it could be 'signed' so that they were
> unawar of it. The macro recorder could help you get started with this and
> there are plenty of web sites offering VBA code and advice on the web.
> --
> View this message in context: 
> http://apache-poi.1045710.n5.nabble.com/large-xssf-files-tp3227625p3228800.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to