Search in sources :

Example 1 with SharedStrings

use of org.docx4j.openpackaging.parts.SpreadsheetML.SharedStrings in project com.revolsys.open by revolsys.

the class XlsxRecordReader method initDo.

@Override
protected void initDo() {
    super.initDo();
    try (InputStream in = this.resource.newBufferedInputStream()) {
        final SpreadsheetMLPackage spreadsheetPackage = (SpreadsheetMLPackage) OpcPackage.load(in);
        final DocPropsCustomPart customProperties = spreadsheetPackage.getDocPropsCustomPart();
        if (customProperties != null) {
            int srid = 0;
            try {
                srid = Integer.parseInt(customProperties.getProperty("srid").getLpwstr());
            } catch (final Throwable e) {
            }
            int axisCount = 2;
            try {
                axisCount = Integer.parseInt(customProperties.getProperty("axisCount").getLpwstr());
                if (axisCount > 4) {
                    axisCount = 2;
                }
            } catch (final Throwable e) {
            }
            double scaleXy = 0;
            try {
                scaleXy = Double.parseDouble(customProperties.getProperty("scaleXy").getLpwstr());
            } catch (final Throwable e) {
            }
            double scaleZ = 0;
            try {
                scaleZ = Double.parseDouble(customProperties.getProperty("scaleZ").getLpwstr());
            } catch (final Throwable e) {
            }
            final GeometryFactory geometryFactory = GeometryFactory.fixed(srid, axisCount, scaleXy, scaleXy, scaleZ);
            setGeometryFactory(geometryFactory);
        }
        WorksheetPart worksheetPart = null;
        for (final Part part : spreadsheetPackage.getParts().getParts().values()) {
            if (part instanceof WorksheetPart) {
                if (worksheetPart == null) {
                    worksheetPart = (WorksheetPart) part;
                }
            } else if (part instanceof SharedStrings) {
                final SharedStrings sharedStrings = (SharedStrings) part;
                final CTSst contents = sharedStrings.getContents();
                this.sharedStringList = contents.getSi();
            }
        }
        if (worksheetPart != null) {
            final Worksheet worksheet = worksheetPart.getContents();
            final SheetData sheetData = worksheet.getSheetData();
            this.rows = sheetData.getRow();
            final List<String> line = readNextRow();
            final String baseName = this.resource.getBaseName();
            newRecordDefinition(baseName, line);
        }
    } catch (final IOException | Docx4JException e) {
        Logs.error(this, "Unable to open " + this.resource, e);
    } catch (final NoSuchElementException e) {
    }
}
Also used : SpreadsheetMLPackage(org.docx4j.openpackaging.packages.SpreadsheetMLPackage) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) InputStream(java.io.InputStream) WorksheetPart(org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart) Worksheet(org.xlsx4j.sml.Worksheet) IOException(java.io.IOException) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException) DocPropsCustomPart(org.docx4j.openpackaging.parts.DocPropsCustomPart) CTSst(org.xlsx4j.sml.CTSst) SheetData(org.xlsx4j.sml.SheetData) WorksheetPart(org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart) DocPropsCustomPart(org.docx4j.openpackaging.parts.DocPropsCustomPart) Part(org.docx4j.openpackaging.parts.Part) SharedStrings(org.docx4j.openpackaging.parts.SpreadsheetML.SharedStrings) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 NoSuchElementException (java.util.NoSuchElementException)1 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)1 SpreadsheetMLPackage (org.docx4j.openpackaging.packages.SpreadsheetMLPackage)1 DocPropsCustomPart (org.docx4j.openpackaging.parts.DocPropsCustomPart)1 Part (org.docx4j.openpackaging.parts.Part)1 SharedStrings (org.docx4j.openpackaging.parts.SpreadsheetML.SharedStrings)1 WorksheetPart (org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart)1 CTSst (org.xlsx4j.sml.CTSst)1 SheetData (org.xlsx4j.sml.SheetData)1 Worksheet (org.xlsx4j.sml.Worksheet)1