Search in sources :

Example 1 with SheetData

use of org.xlsx4j.sml.SheetData in project Aspose.Cells-for-Java by aspose-cells.

the class Xlsx4jAddComments method addContent.

private static void addContent(WorksheetPart sheet) throws JAXBException, Docx4JException {
    // Minimal content already present
    SheetData sheetData = sheet.getContents().getSheetData();
    // Now add
    Row row = Context.getsmlObjectFactory().createRow();
    Cell cell = Context.getsmlObjectFactory().createCell();
    cell.setV("1234");
    row.getC().add(cell);
    row.getC().add(createCell("hello world!"));
    sheetData.getRow().add(row);
    // ADD A COMMENT TO CELL A1
    CommentsPart cp = new CommentsPart();
    cp.setContents(createComment("A1"));
    sheet.addTargetPart(cp);
    // Add <legacyDrawing r:id="rId1"/>
    VMLPart vmlPart = new VMLPart();
    // corresponds to A1
    vmlPart.setContents(getVml(0, 0));
    // you'll need extra VML for each comment
    Relationship rel = sheet.addTargetPart(vmlPart);
    CTLegacyDrawing legacyDrawing = Context.getsmlObjectFactory().createCTLegacyDrawing();
    legacyDrawing.setId(rel.getId());
    sheet.getContents().setLegacyDrawing(legacyDrawing);
}
Also used : SheetData(org.xlsx4j.sml.SheetData) CommentsPart(org.docx4j.openpackaging.parts.SpreadsheetML.CommentsPart) Relationship(org.docx4j.relationships.Relationship) VMLPart(org.docx4j.openpackaging.parts.VMLPart) Row(org.xlsx4j.sml.Row) Cell(org.xlsx4j.sml.Cell) CTLegacyDrawing(org.xlsx4j.sml.CTLegacyDrawing)

Example 2 with SheetData

use of org.xlsx4j.sml.SheetData 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)

Example 3 with SheetData

use of org.xlsx4j.sml.SheetData in project Aspose.Cells-for-Java by aspose-cells.

the class Xlsx4jNewSpreadSheet method addContent.

private static void addContent(WorksheetPart sheet) {
    // Minimal content already present
    SheetData sheetData = sheet.getJaxbElement().getSheetData();
    // Now add
    Row row = Context.getsmlObjectFactory().createRow();
    Cell cell = Context.getsmlObjectFactory().createCell();
    cell.setV("1234");
    row.getC().add(cell);
    row.getC().add(createCell("hello world!"));
    sheetData.getRow().add(row);
}
Also used : SheetData(org.xlsx4j.sml.SheetData) Row(org.xlsx4j.sml.Row) Cell(org.xlsx4j.sml.Cell)

Example 4 with SheetData

use of org.xlsx4j.sml.SheetData in project Aspose.Cells-for-Java by aspose-cells.

the class Xlsx4jHeightAdjustment method main.

/**
 * @param args
 * @throws JAXBException
 * @throws Docx4JException
 */
public static void main(String[] args) throws JAXBException, Docx4JException {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(Xlsx4jHeightAdjustment.class);
    // TODO Auto-generated method stub
    SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
    WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);
    CTSheetFormatPr format = Context.getsmlObjectFactory().createCTSheetFormatPr();
    format.setDefaultRowHeight(5);
    format.setCustomHeight(Boolean.TRUE);
    sheet.getJaxbElement().setSheetFormatPr(format);
    SheetData sheetData = sheet.getJaxbElement().getSheetData();
    Row row = Context.getsmlObjectFactory().createRow();
    row.setHt(66.0);
    row.setCustomHeight(Boolean.TRUE);
    row.setR(1L);
    Cell cell1 = Context.getsmlObjectFactory().createCell();
    cell1.setV("1234");
    row.getC().add(cell1);
    Cell cell2 = Context.getsmlObjectFactory().createCell();
    cell2.setV("56");
    row.getC().add(cell2);
    sheetData.getRow().add(row);
    SaveToZipFile saver = new SaveToZipFile(pkg);
    saver.save(dataDir + "RowHeight-Xlsx4j.xlsx");
}
Also used : SpreadsheetMLPackage(org.docx4j.openpackaging.packages.SpreadsheetMLPackage) PartName(org.docx4j.openpackaging.parts.PartName) SheetData(org.xlsx4j.sml.SheetData) WorksheetPart(org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart) SaveToZipFile(org.docx4j.openpackaging.io.SaveToZipFile) Row(org.xlsx4j.sml.Row) CTSheetFormatPr(org.xlsx4j.sml.CTSheetFormatPr) Cell(org.xlsx4j.sml.Cell)

Aggregations

SheetData (org.xlsx4j.sml.SheetData)4 Cell (org.xlsx4j.sml.Cell)3 Row (org.xlsx4j.sml.Row)3 SpreadsheetMLPackage (org.docx4j.openpackaging.packages.SpreadsheetMLPackage)2 WorksheetPart (org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart)2 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 SaveToZipFile (org.docx4j.openpackaging.io.SaveToZipFile)1 DocPropsCustomPart (org.docx4j.openpackaging.parts.DocPropsCustomPart)1 Part (org.docx4j.openpackaging.parts.Part)1 PartName (org.docx4j.openpackaging.parts.PartName)1 CommentsPart (org.docx4j.openpackaging.parts.SpreadsheetML.CommentsPart)1 SharedStrings (org.docx4j.openpackaging.parts.SpreadsheetML.SharedStrings)1 VMLPart (org.docx4j.openpackaging.parts.VMLPart)1 Relationship (org.docx4j.relationships.Relationship)1 CTLegacyDrawing (org.xlsx4j.sml.CTLegacyDrawing)1 CTSheetFormatPr (org.xlsx4j.sml.CTSheetFormatPr)1