Search in sources :

Example 1 with CellAnchor

use of net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor in project translationstudio8 by heartsome.

the class XliffReader method readSheet.

private void readSheet(List<SheetPart> sheetList, IProgressMonitor monitor) throws InternalFileException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask(Messages.getString("msexcel.xliff2mse.task4"), sheetList.size() * 5);
    List<String> sheetNames = new ArrayList<String>();
    for (SheetPart sp : sheetList) {
        monitor.worked(1);
        String name = sp.getName();
        name = processContent(name);
        // 处理重复名称
        int i = 1;
        while (sheetNames.contains(name)) {
            name += i;
            i++;
        }
        sheetNames.add(name);
        sp.setSheetName(name);
        // read headers
        monitor.worked(1);
        List<HeaderFooter> headers = sp.getHeader();
        for (HeaderFooter hf : headers) {
            String content = hf.getContent();
            content = processContent(content);
            hf.setContent(content);
        }
        // update the file
        sp.setHeaderFooter(headers);
        monitor.worked(1);
        DrawingsPart drawingp = sp.getDrawingsPart();
        if (drawingp != null) {
            List<CellAnchor> aList = drawingp.getCellAnchorList();
            for (CellAnchor a : aList) {
                List<ShapeTxBody> sList = a.getShapeList();
                if (sList.size() == 0) {
                    continue;
                }
                for (ShapeTxBody s : sList) {
                    List<ShapeParagraph> pList = s.getTxBodyParagraghList();
                    for (ShapeParagraph p : pList) {
                        String content = p.getXmlContent();
                        content = processContent(content);
                        p.setXmlContent(content);
                    }
                }
            }
            drawingp.updateDrawingObject();
        }
        monitor.worked(1);
        List<Cell> cellList = sp.getCells("s");
        for (Cell c : cellList) {
            String content = c.getFullContent();
            content = processContent(content);
            c.setShareStringItemFullContent(content);
        }
        monitor.worked(1);
        // read footer
        List<HeaderFooter> footers = sp.getFoolter();
        for (HeaderFooter hf : footers) {
            String content = hf.getContent();
            content = processContent(content);
            hf.setContent(content);
        }
        // update the file
        sp.setHeaderFooter(footers);
    }
    monitor.done();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ArrayList(java.util.ArrayList) HeaderFooter(net.heartsome.cat.converter.msexcel2007.document.HeaderFooter) ShapeParagraph(net.heartsome.cat.converter.msexcel2007.document.drawing.ShapeParagraph) SheetPart(net.heartsome.cat.converter.msexcel2007.document.SheetPart) ShapeTxBody(net.heartsome.cat.converter.msexcel2007.document.drawing.ShapeTxBody) CellAnchor(net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor) DrawingsPart(net.heartsome.cat.converter.msexcel2007.document.DrawingsPart) Cell(net.heartsome.cat.converter.msexcel2007.document.Cell)

Example 2 with CellAnchor

use of net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor in project translationstudio8 by heartsome.

the class DrawingsPart method loadShapeAnchor.

private void loadShapeAnchor() {
    cellAnchorList = new ArrayList<CellAnchor>();
    AutoPilot ap = getAutoPilot();
    try {
        ap.selectXPath("/xdr:wsDr/xdr:twoCellAnchor | xdr:oneCellAnchor");
        while (ap.evalXPath() != -1) {
            String anchorXML = vu.getElementFragment();
            String fromCol = vu.getElementContent("./xdr:from/xdr:col");
            String fromRow = vu.getElementContent("./xdr:from/xdr:row");
            CellAnchor a = new CellAnchor(anchorXML, fromRow, fromCol);
            cellAnchorList.add(a);
        }
    } catch (VTDException e) {
    }
    // sort by row&col ASC
    if (cellAnchorList.size() > 0) {
        Collections.sort(cellAnchorList, new Comparator<CellAnchor>() {

            public int compare(CellAnchor o1, CellAnchor o2) {
                int o1r = Integer.parseInt(o1.getFromRow());
                int o2r = Integer.parseInt(o2.getFromRow());
                int o1c = Integer.parseInt(o1.getFromCol());
                int o2c = Integer.parseInt(o2.getFromCol());
                if (o1r != o2r) {
                    return o1r - o2r;
                } else {
                    return o1c - o2c;
                }
            }
        });
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) CellAnchor(net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor)

Example 3 with CellAnchor

use of net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor in project translationstudio8 by heartsome.

the class SpreadsheetReader method readDrawings.

private void readDrawings(DrawingsPart drawingp) throws IOException {
    List<CellAnchor> aList = drawingp.getCellAnchorList();
    for (CellAnchor a : aList) {
        List<ShapeTxBody> sList = a.getShapeList();
        if (sList.size() == 0) {
            continue;
        }
        for (ShapeTxBody s : sList) {
            List<ShapeParagraph> pList = s.getTxBodyParagraghList();
            for (ShapeParagraph p : pList) {
                String txt = p.getParagraghText();
                if (txt.length() == 0) {
                    continue;
                }
                List<Object[]> txtStyle = p.getParagraghCharacterStyle();
                String[] segs = segmenter.segment(txt);
                StringBuffer bf = new StringBuffer();
                for (String seg : segs) {
                    if (txtStyle.size() > 1) {
                        List<Object[]> style = ReaderUtil.getSegStyle(txtStyle, seg, txt);
                        if (style.size() != 0) {
                            seg = ReaderUtil.appendSegStyle(seg, style);
                        }
                    }
                    bf.append("%%%").append(xliffIdex).append("%%%");
                    writeXliffFile(xliffIdex, seg);
                    xliffIdex++;
                }
                // System.out.println(bf.toString());
                p.setParagraghText(bf.toString());
            }
        }
    }
}
Also used : ShapeParagraph(net.heartsome.cat.converter.msexcel2007.document.drawing.ShapeParagraph) ShapeTxBody(net.heartsome.cat.converter.msexcel2007.document.drawing.ShapeTxBody) CellAnchor(net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor)

Example 4 with CellAnchor

use of net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor in project translationstudio8 by heartsome.

the class DrawingsPart method updateDrawingObject.

public void updateDrawingObject() throws InternalFileException {
    StringBuffer bf = new StringBuffer();
    for (CellAnchor c : cellAnchorList) {
        c.updateCellAnchor();
        bf.append(c.getXmlContent());
    }
    vu.update(getAutoPilot(), xm, "/xdr:wsDr/text()", bf.toString());
    save();
}
Also used : CellAnchor(net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor)

Aggregations

CellAnchor (net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor)4 ShapeParagraph (net.heartsome.cat.converter.msexcel2007.document.drawing.ShapeParagraph)2 ShapeTxBody (net.heartsome.cat.converter.msexcel2007.document.drawing.ShapeTxBody)2 AutoPilot (com.ximpleware.AutoPilot)1 VTDException (com.ximpleware.VTDException)1 ArrayList (java.util.ArrayList)1 Cell (net.heartsome.cat.converter.msexcel2007.document.Cell)1 DrawingsPart (net.heartsome.cat.converter.msexcel2007.document.DrawingsPart)1 HeaderFooter (net.heartsome.cat.converter.msexcel2007.document.HeaderFooter)1 SheetPart (net.heartsome.cat.converter.msexcel2007.document.SheetPart)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1