use of net.heartsome.cat.converter.msexcel2007.document.SheetPart 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();
}
}
use of net.heartsome.cat.converter.msexcel2007.document.SheetPart 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();
}
use of net.heartsome.cat.converter.msexcel2007.document.SheetPart 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) {
}
}
use of net.heartsome.cat.converter.msexcel2007.document.SheetPart in project translationstudio8 by heartsome.
the class SpreadsheetReader method read2XliffFile.
/**
* 将内容读入到XLIFF文件
* @param xlfOs
* XLIFF文件BufferWriter
* @param filterRedCell
* 是否需要过滤标记为红色的单元格
* @param monitor
* @throws InternalFileException
* @throws IOException
* ;
*/
public void read2XliffFile(String inputFile, BufferedWriter xlfOs, String sklFilePath, boolean filterRedCell, IProgressMonitor monitor) throws InternalFileException, IOException {
this.xlfOs = xlfOs;
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", 5);
try {
monitor.setTaskName(Messages.getString("msexcel.mse2xliff.task2"));
// open source file
SpreadsheetDocument.open(inputFile);
monitor.worked(1);
monitor.setTaskName(Messages.getString("msexcel.mse2xliff.task3"));
// load current workbook
WorkBookPart wb = SpreadsheetDocument.workBookPart;
if (filterRedCell) {
this.filterStyleIndex = wb.getStylesPart().getFilterCellStyle();
}
// read worksheet
List<SheetPart> sheetList = wb.getSheetParts();
readSheets(sheetList, new SubProgressMonitor(monitor, 2));
// save current document
wb.save();
monitor.worked(1);
monitor.setTaskName(Messages.getString("msexcel.mse2xliff.task4"));
// generate skl file
saveSklFile(sklFilePath);
monitor.worked(1);
} finally {
SpreadsheetDocument.close();
}
monitor.done();
}
use of net.heartsome.cat.converter.msexcel2007.document.SheetPart in project translationstudio8 by heartsome.
the class SpreadsheetReader method readSheets.
private void readSheets(List<SheetPart> sheetList, IProgressMonitor monitor) throws InternalFileException, IOException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", sheetList.size() * 5);
for (SheetPart sp : sheetList) {
// process sheet name
String name = sp.getName();
writeXliffFile(xliffIdex, name);
sp.setSheetName("%%%" + xliffIdex + "%%%");
xliffIdex++;
monitor.worked(1);
// read headers
List<HeaderFooter> headers = sp.getHeader();
readHeaderFooters(headers);
// update the file
sp.setHeaderFooter(headers);
monitor.worked(1);
// read drawing part
DrawingsPart drawingp = sp.getDrawingsPart();
if (drawingp != null) {
readDrawings(drawingp);
drawingp.updateDrawingObject();
}
monitor.worked(1);
List<Cell> cellList = sp.getCells("s");
for (Cell c : cellList) {
if (filterStyleIndex.contains(c.getStyleIndex())) {
// skip this cell
continue;
}
String cellText = c.getValue();
if (cellText == null || cellText.trim().length() == 0) {
// ignore the cell
continue;
}
List<Object[]> cellStyle = c.getCellCharacterStyles();
String[] segs = segmenter.segment(cellText);
StringBuffer bf = new StringBuffer();
for (String seg : segs) {
List<Object[]> s = ReaderUtil.getSegStyle(cellStyle, seg, cellText);
if (s.size() != 0) {
seg = ReaderUtil.appendSegStyle(seg, s);
}
bf.append("%%%").append(xliffIdex++).append("%%%");
// System.out.println(xliffIdex + ":" + seg);
writeXliffFile(xliffIdex - 1, seg);
}
c.setValue(bf.toString());
}
monitor.worked(1);
// read headers
List<HeaderFooter> footers = sp.getFoolter();
readHeaderFooters(footers);
// update the file
sp.setHeaderFooter(footers);
monitor.worked(1);
}
monitor.done();
}
Aggregations