本文整理匯總了Java中org.docx4j.openpackaging.packages.SpreadsheetMLPackage類的典型用法代碼示例。如果您正苦於以下問題:Java SpreadsheetMLPackage類的具體用法?Java SpreadsheetMLPackage怎麽用?Java SpreadsheetMLPackage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SpreadsheetMLPackage類屬於org.docx4j.openpackaging.packages包,在下文中一共展示了SpreadsheetMLPackage類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: inlineToXlsx
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
@Override
public void inlineToXlsx(SpreadsheetMLPackage pkg, WorksheetPart worksheetPart, Cell newCell, Object paramValue, Matcher matcher) {
try {
Image image = new Image(paramValue, matcher);
if (image.isValid()) {
BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(pkg, worksheetPart, image.imageContent);
CTOneCellAnchor anchor = new CTOneCellAnchor();
anchor.setFrom(new CTMarker());
CellReference cellReference = new CellReference("", newCell.getR());
anchor.getFrom().setCol(cellReference.getColumn() - 1);
anchor.getFrom().setRow(cellReference.getRow() - 1);
anchor.setExt(new CTPositiveSize2D());
anchor.getExt().setCx(XlsxUtils.convertPxToEmu(image.width));
anchor.getExt().setCy(XlsxUtils.convertPxToEmu(image.height));
newCell.setV(null);
putImage(worksheetPart, pkg, imagePart, anchor);
}
} catch (Exception e) {
throw new ReportFormattingException("An error occurred while inserting bitmap to xlsx file", e);
}
}
示例2: main
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
/**
* @param args
* @throws JAXBException
* @throws Docx4JException
*/
public static void main(String[] args) throws JAXBException, Docx4JException {
// TODO Auto-generated method stub
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/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( System.getProperty("user.dir") + "/data/xlsx4j/RowHeight-Xlsx4j.xlsx");
}
示例3: main
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
String outputfilepath = System.getProperty("user.dir") + "/data/xlsx4j/AddImage-Xlsx4j.xlsx";
String imagefilePath = System.getProperty("user.dir") + "/data/xlsx4j/greentick.png" ;
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
WorksheetPart worksheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);
// Create Drawing part and add to sheet
Drawing drawingPart = new Drawing();
Relationship drawingRel = worksheet.addTargetPart(drawingPart);
// Add anchor XML to worksheet
org.xlsx4j.sml.CTDrawing drawing = org.xlsx4j.jaxb.Context.getsmlObjectFactory().createCTDrawing();
worksheet.getJaxbElement().setDrawing(drawing);
drawing.setId( drawingRel.getId() );
// Create image part and add to Drawing part
BinaryPartAbstractImage imagePart
= BinaryPartAbstractImage.createImagePart(pkg, drawingPart,
FileUtils.readFileToByteArray(new File(imagefilePath) ));
String imageRelID = imagePart.getSourceRelationship().getId();
// Create and set drawing part content
// Take your pick ..
// .. build it using code
// drawingPart.setJaxbElement(
// buildDrawingPartContentUsingCode(imageRelID));
// .. or build it from an XML string
drawingPart.setJaxbElement(
buildDrawingPartContentFromXmlString(imageRelID));
// Save the xlsx
SaveToZipFile saver = new SaveToZipFile(pkg);
saver.save(outputfilepath);
System.out.println("\n\n done .. " + outputfilepath);
}
示例4: create
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
public static Document create(SpreadsheetMLPackage thePackage) {
Document document = new Document();
document.thePackage = thePackage;
RelationshipsPart rp = thePackage.getRelationshipsPart();
document.traverse(null, rp);
return document;
}
示例5: init
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
protected void init() {
try {
template = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent()));
result = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent()));
result.getWorkbook().getCalcPr().setCalcMode(STCalcMode.AUTO);
result.getWorkbook().getCalcPr().setFullCalcOnLoad(true);
marshaller = XmlCopyUtils.createMarshaller(Context.jcSML);
unmarshaller = XmlCopyUtils.createUnmarshaller(Context.jcSML);
} catch (Exception e) {
throw wrapWithReportingException(String.format("An error occurred while loading template [%s]", reportTemplate.getDocumentName()), e);
}
}
示例6: compareFiles
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
private void compareFiles(String resultPath, String etalonPath) throws Docx4JException {
Document result = Document.create(SpreadsheetMLPackage.load(new File(resultPath)));
Document etalon = Document.create(SpreadsheetMLPackage.load(new File(etalonPath)));
List<Document.SheetWrapper> resultWorksheets = result.getWorksheets();
List<Document.SheetWrapper> etalonWorksheets = etalon.getWorksheets();
for (int i = 0; i < resultWorksheets.size(); i++) {
Document.SheetWrapper resultWorksheet = resultWorksheets.get(i);
Document.SheetWrapper etalonWorksheet = etalonWorksheets.get(i);
List<Row> resultRows = resultWorksheet.getWorksheet().getContents().getSheetData().getRow();
List<Row> etalonRows = etalonWorksheet.getWorksheet().getContents().getSheetData().getRow();
for (int j = 0, rowSize = resultRows.size(); j < rowSize; j++) {
Row resultRow = resultRows.get(j);
Row etalonRow = etalonRows.get(j);
List<Cell> resultCells = resultRow.getC();
List<Cell> etalonCells = etalonRow.getC();
for (int i1 = 0, cSize = etalonCells.size(); i1 < cSize; i1++) {
Cell resultCell = resultCells.get(i1);
Cell etalonCell = etalonCells.get(i1);
if (resultCell.getF() != null) {
Assert.assertEquals(etalonCell.getF().getValue(), resultCell.getF().getValue());
} else {
Assert.assertEquals(etalonCell.getV(), resultCell.getV());
}
}
}
}
}
示例7: main
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
/**
* @param args
*/
public static void main(String[] args) {
try {
String outputfilepath = System.getProperty("user.dir") + "/data/xlsx4j/AddComments-Xlsx4j.xlsx";
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);
addContent(sheet);
pkg.save(new File(outputfilepath));
System.out.println("\n\n done .. " + outputfilepath);
}
catch (Exception e)
{
e.printStackTrace();
}
}
示例8: getPackage
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
public SpreadsheetMLPackage getPackage() {
return thePackage;
}
示例9: putImage
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
private void putImage(WorksheetPart worksheetPart, SpreadsheetMLPackage pkg, BinaryPartAbstractImage imagePart, CTOneCellAnchor anchor) throws Docx4JException {
PartName drawingPart = new PartName(worksheetPart.getPartName().getName().replace("worksheets/sheet", "drawings/drawing"));
String imagePartName = imagePart.getPartName().getName();
Drawing drawing = (Drawing) pkg.getParts().get(drawingPart);
int currentId = 0;
if (drawing == null) {
drawing = new Drawing(drawingPart);
drawing.setContents(new org.docx4j.dml.spreadsheetdrawing.CTDrawing());
Relationship relationship = worksheetPart.addTargetPart(drawing);
org.xlsx4j.sml.CTDrawing smlDrawing = new org.xlsx4j.sml.CTDrawing();
smlDrawing.setId(relationship.getId());
smlDrawing.setParent(worksheetPart.getContents());
worksheetPart.getContents().setDrawing(smlDrawing);
} else {
currentId = drawing.getContents().getEGAnchor().size();
}
CTPicture picture = new CTPicture();
CTBlipFillProperties blipFillProperties = new CTBlipFillProperties();
blipFillProperties.setStretch(new CTStretchInfoProperties());
blipFillProperties.getStretch().setFillRect(new CTRelativeRect());
blipFillProperties.setBlip(new CTBlip());
blipFillProperties.getBlip().setEmbed("rId" + (currentId + 1));
blipFillProperties.getBlip().setCstate(STBlipCompression.PRINT);
picture.setBlipFill(blipFillProperties);
CTNonVisualDrawingProps nonVisualDrawingProps = new CTNonVisualDrawingProps();
nonVisualDrawingProps.setId(currentId + 2);
nonVisualDrawingProps.setName(imagePartName.substring(imagePartName.lastIndexOf("/") + 1));
nonVisualDrawingProps.setDescr(nonVisualDrawingProps.getName());
CTNonVisualPictureProperties nonVisualPictureProperties = new CTNonVisualPictureProperties();
nonVisualPictureProperties.setPicLocks(new CTPictureLocking());
nonVisualPictureProperties.getPicLocks().setNoChangeAspect(true);
CTPictureNonVisual nonVisualPicture = new CTPictureNonVisual();
nonVisualPicture.setCNvPr(nonVisualDrawingProps);
nonVisualPicture.setCNvPicPr(nonVisualPictureProperties);
picture.setNvPicPr(nonVisualPicture);
CTShapeProperties shapeProperties = new CTShapeProperties();
CTTransform2D transform2D = new CTTransform2D();
transform2D.setOff(new CTPoint2D());
transform2D.setExt(new CTPositiveSize2D());
shapeProperties.setXfrm(transform2D);
shapeProperties.setPrstGeom(new CTPresetGeometry2D());
shapeProperties.getPrstGeom().setPrst(STShapeType.RECT);
shapeProperties.getPrstGeom().setAvLst(new CTGeomGuideList());
picture.setSpPr(shapeProperties);
anchor.setPic(picture);
anchor.setClientData(new CTAnchorClientData());
drawing.getContents().getEGAnchor().add(anchor);
Relationship rel = new Relationship();
rel.setId("rId" + (currentId + 1));
rel.setType(Namespaces.IMAGE);
rel.setTarget(imagePartName);
drawing.getRelationshipsPart().addRelationship(rel);
RelationshipsPart relPart = drawing.getRelationshipsPart();
pkg.getParts().remove(relPart.getPartName());
pkg.getParts().put(relPart);
pkg.getParts().remove(drawing.getPartName());
pkg.getParts().put(drawing);
}
示例10: inlineToXlsx
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
@Override
public void inlineToXlsx(SpreadsheetMLPackage pkg, WorksheetPart worksheetPart, Cell newCell, Object paramValue, Matcher matcher) {
throw new UnsupportedOperationException("Inline html content to XSLX is not supported");
}
示例11: writeToOutputStream
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
protected void writeToOutputStream(SpreadsheetMLPackage mlPackage, OutputStream outputStream) throws Docx4JException {
SaveToZipFile saver = new SaveToZipFile(mlPackage);
saver.save(outputStream);
}
示例12: main
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
String outputfilepath = "data/xlsx4j/newWorksheet_Xlsx4j.xlsx";
SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);
addContent(sheet);
SaveToZipFile saver = new SaveToZipFile(pkg);
saver.save(outputfilepath);
System.out.println("\n\n done .. " + outputfilepath);
}
示例13: inlineToXlsx
import org.docx4j.openpackaging.packages.SpreadsheetMLPackage; //導入依賴的package包/類
/**
* Inline content to xlsx template
*/
void inlineToXlsx(SpreadsheetMLPackage pkg, WorksheetPart worksheetPart, Cell newCell, Object paramValue, Matcher matcher);