Search in sources :

Example 41 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class SheetPart method getCells.

public List<Cell> getCells(String dataType) throws InternalFileException {
    cellList = new ArrayList<Cell>();
    String xpath = "/worksheet/sheetData/row/c[@t='" + dataType + "']";
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    try {
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            Hashtable<String, String> attrs = vu.getCurrentElementAttributs();
            SpreadsheetUtil.assertNull(attrs);
            String styleIndex = attrs.get("s");
            styleIndex = styleIndex == null ? "-1" : styleIndex;
            String val = vu.getChildContent("v");
            val = val == null ? "" : val;
            Cell cell = new Cell(val, Integer.parseInt(styleIndex), dataType);
            cellList.add(cell);
        }
    } catch (VTDException e) {
        logger.error("", e);
    }
    return cellList;
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot)

Example 42 with AutoPilot

use of com.ximpleware.AutoPilot 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 43 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class StylesPart method isRedColor.

/**
	 * 加载红前景色样式
	 */
private boolean isRedColor(int idx) {
    idx += 1;
    String xpath = "/styleSheet/fonts/font[" + idx + "]";
    try {
        vu.getVTDNav().push();
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            String rgb = vu.getElementAttribute("./color", "rgb");
            if (rgb != null && rgb.equals("FFFF0000")) {
                return true;
            }
        }
        vu.getVTDNav().pop();
    } catch (VTDException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot)

Example 44 with AutoPilot

use of com.ximpleware.AutoPilot 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)

Example 45 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class AbstractDrawing method getDeclareNSAutoPilot.

/**
	 * 获取带有命名空间申明的AtutoPilot对象
	 * @return ;
	 */
protected AutoPilot getDeclareNSAutoPilot() {
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    ap.declareXPathNameSpace(Constants.NAMESPACE_DRAWING_PREFIX_XDR, Constants.NAMESPACE_DRAWING_URL_XDR);
    ap.declareXPathNameSpace(Constants.NAMESPACE_DRAWING_PREFIX_A, Constants.NAMESPACE_DRAWING_URL_A);
    return ap;
}
Also used : AutoPilot(com.ximpleware.AutoPilot)

Aggregations

AutoPilot (com.ximpleware.AutoPilot)308 VTDNav (com.ximpleware.VTDNav)173 NavException (com.ximpleware.NavException)150 XPathParseException (com.ximpleware.XPathParseException)145 XPathEvalException (com.ximpleware.XPathEvalException)137 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)112 IOException (java.io.IOException)103 ModifyException (com.ximpleware.ModifyException)95 TranscodeException (com.ximpleware.TranscodeException)82 CoreException (org.eclipse.core.runtime.CoreException)76 UnsupportedEncodingException (java.io.UnsupportedEncodingException)58 VTDGen (com.ximpleware.VTDGen)50 FileNotFoundException (java.io.FileNotFoundException)49 XMLModifier (com.ximpleware.XMLModifier)46 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)44 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)39 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)34 LinkedList (java.util.LinkedList)25