Search in sources :

Example 1 with InternalFileException

use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException in project translationstudio8 by heartsome.

the class XliffReader method read2SpreadsheetDoc.

public void read2SpreadsheetDoc(String spreadsheetDocFile, String xliffFile, String sklFile, IProgressMonitor monitor) throws InternalFileException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask(Messages.getString("msexcel.xliff2mse.task1"), 5);
    loadFile(xliffFile);
    monitor.worked(1);
    monitor.setTaskName(Messages.getString("msexcel.xliff2mse.task2"));
    try {
        SpreadsheetDocument.open(sklFile);
        monitor.worked(1);
        WorkBookPart wb = SpreadsheetDocument.workBookPart;
        List<SheetPart> sheetList = wb.getSheetParts();
        readSheet(sheetList, new SubProgressMonitor(monitor, 1));
        monitor.setTaskName(Messages.getString("msexcel.xliff2mse.task3"));
        wb.save();
        monitor.worked(1);
        try {
            ZipUtil.zipFolder(spreadsheetDocFile, SpreadsheetDocument.spreadsheetPackage.getPackageSuperRoot());
        } catch (IOException e) {
            logger.error("", e);
        }
        monitor.worked(1);
    } finally {
        SpreadsheetDocument.close();
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) WorkBookPart(net.heartsome.cat.converter.msexcel2007.document.WorkBookPart) SheetPart(net.heartsome.cat.converter.msexcel2007.document.SheetPart) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 2 with InternalFileException

use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException 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 3 with InternalFileException

use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException in project translationstudio8 by heartsome.

the class SheetPart method loadDrawingsPart.

private void loadDrawingsPart() throws InternalFileException {
    String xpath = "/worksheet/drawing";
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    try {
        ap.selectXPath(xpath);
        if (ap.evalXPath() != -1) {
            Hashtable<String, String> attrs = vu.getCurrentElementAttributs();
            SpreadsheetUtil.assertNull(attrs);
            String rId = attrs.get("r:id");
            Relationship r = relsPart.getRelationshipById(rId);
            SpreadsheetUtil.assertNull(r);
            SpreadsheetDocument.spreadsheetPackage.markRoot();
            try {
                this.drawingsPart = new DrawingsPart(r.getTarget());
            } catch (FileNotFoundException e) {
            // no drawingsPart
            }
            SpreadsheetDocument.spreadsheetPackage.resetRoot();
        }
    } catch (VTDException e) {
        logger.error("", e);
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) Relationship(net.heartsome.cat.converter.msexcel2007.document.rels.Relationship) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with InternalFileException

use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException in project translationstudio8 by heartsome.

the class WorkBookPart method loadSytlesPart.

private void loadSytlesPart() throws InternalFileException, FileNotFoundException {
    List<Relationship> rList = relsPart.getRelationshipByType(Constants.PART_TYPE_STYLE);
    if (rList.size() != 1) {
        throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
    }
    Relationship r = rList.get(0);
    stylePart = new StylesPart(r.getTarget());
}
Also used : Relationship(net.heartsome.cat.converter.msexcel2007.document.rels.Relationship) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException)

Example 5 with InternalFileException

use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException in project translationstudio8 by heartsome.

the class WorkBookPart method loadWorkSheets.

private void loadWorkSheets() throws InternalFileException, FileNotFoundException {
    sheetPartList = new ArrayList<SheetPart>();
    int ssiIndex = 0;
    StringBuffer siBf = new StringBuffer();
    try {
        String xpath = "/workbook/sheets/sheet";
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            int index = vu.getVTDNav().getAttrVal("name");
            if (index == -1) {
                throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
            }
            String name = vu.getVTDNav().toRawString(index);
            index = vu.getVTDNav().getAttrVal("sheetId");
            if (index == -1) {
                throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
            }
            String id = vu.getVTDNav().toRawString(index);
            index = vu.getVTDNav().getAttrVal("r:id");
            if (index == -1) {
                throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
            }
            String rid = vu.getVTDNav().toRawString(index);
            Relationship r = relsPart.getRelationshipById(rid);
            SpreadsheetUtil.assertNull(r);
            String target = r.getTarget();
            SheetPart sp = new SheetPart(name, id, target);
            ssiIndex = sp.fillShareStringTable(sst, ssiIndex, siBf);
            sheetPartList.add(sp);
        }
        // fix bug Bug #2925 转换excel文件--空指针异常,转换失败 by jason
        if (sst != null && siBf.length() != 0) {
            sst.updateShareStringTable(siBf.toString());
        }
    } catch (VTDException e) {
        logger.error("", e);
    } catch (IOException e) {
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) Relationship(net.heartsome.cat.converter.msexcel2007.document.rels.Relationship) IOException(java.io.IOException) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException)

Aggregations

VTDException (com.ximpleware.VTDException)7 InternalFileException (net.heartsome.cat.converter.msexcel2007.common.InternalFileException)7 IOException (java.io.IOException)5 AutoPilot (com.ximpleware.AutoPilot)4 SheetPart (net.heartsome.cat.converter.msexcel2007.document.SheetPart)4 Relationship (net.heartsome.cat.converter.msexcel2007.document.rels.Relationship)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 File (java.io.File)3 VTDGen (com.ximpleware.VTDGen)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Cell (net.heartsome.cat.converter.msexcel2007.document.Cell)2 DrawingsPart (net.heartsome.cat.converter.msexcel2007.document.DrawingsPart)2 HeaderFooter (net.heartsome.cat.converter.msexcel2007.document.HeaderFooter)2 WorkBookPart (net.heartsome.cat.converter.msexcel2007.document.WorkBookPart)2 CellAnchor (net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor)2 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 XMLModifier (com.ximpleware.XMLModifier)1 FileOutputStream (java.io.FileOutputStream)1