List of usage examples for org.apache.poi.xwpf.usermodel XWPFTableRow addNewTableCell
public XWPFTableCell addNewTableCell()
From source file:ch.admin.isb.hermes5.business.word.TranslationWordAdapter.java
License:Apache License
public byte[] write(List<TranslateableText> texts, String lang) { XWPFDocument document = new XWPFDocument(); // insert text into first row XWPFTable table = document.createTable(); table.setCellMargins(0, 100, 0, 100); XWPFTableRow rowOne = table.getRow(0); TranslateableText first = texts.get(0); rowOne.getCell(0).setText(first.getElementIdentifier() + "/ " + first.getTextIdentifier()); rowOne.addNewTableCell().setText(getText(first, lang)); if (isDirty(first, lang)) { rowOne.getCell(1).setColor("FFFF99"); }//from ww w . ja va 2s .c o m // add more rows and insert text if (texts.size() > 1) { for (int c = 1; c < texts.size(); c++) { TranslateableText text = texts.get(c); XWPFTableRow row = table.createRow(); row.getCell(0).setText(text.getElementIdentifier() + "/ " + text.getTextIdentifier()); row.getCell(1).setText(getText(text, lang)); if (isDirty(text, lang)) { row.getCell(1).setColor("FFFF99"); } } } try { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); document.write(outStream); return outStream.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.crimelab.service.PolygraphServiceImpl.java
@Override public XWPFDocument create(Polygraph polygraph, HttpSession session) { XWPFDocument document = null;/* www.j a v a2 s . c o m*/ //Insert into dbase // polygraphDAO.polygraphInfo(polygraph); try { //Blank Document InputStream inpDocx = session.getServletContext() .getResourceAsStream("/WEB-INF/templates/Polygraph.docx"); document = new XWPFDocument(inpDocx); //create Paragraph XWPFParagraph subjectNo = document.createParagraph(); XWPFRun r1 = subjectNo.createRun(); r1.setText("POLYGRAPH SUBJECT NO: " + polygraph.getSubjectNo()); subjectNo.setAlignment(ParagraphAlignment.CENTER); r1.setBold(true); ; //create table XWPFTable table = document.createTable(); //width CTTbl tableFix = table.getCTTbl(); CTTblPr pr = tableFix.getTblPr(); CTTblWidth tblW = pr.getTblW(); tblW.setW(BigInteger.valueOf(4800)); tblW.setType(STTblWidth.PCT); pr.setTblW(tblW); tableFix.setTblPr(pr); //create first row XWPFTableRow tableRowOne = table.getRow(0); XWPFTableCell headerCell = tableRowOne.getCell(0); XWPFParagraph headerParagraph = headerCell.getParagraphs().get(0); XWPFRun hRun = headerParagraph.createRun(); headerCell.setColor("CDCDB4"); hRun.setText("PERSONAL INFORMATION"); tableRowOne.addNewTableCell().setText(null); headerParagraph.setAlignment(ParagraphAlignment.CENTER); XWPFTableCell photoHeaderCell = tableRowOne.getCell(1); XWPFParagraph photoHeaderParagraph = photoHeaderCell.getParagraphs().get(0); XWPFRun pRun = photoHeaderParagraph.createRun(); photoHeaderCell.setColor("CDCDB4"); pRun.setText("PHOTO"); photoHeaderParagraph.setAlignment(ParagraphAlignment.CENTER); XWPFTableRow tableRowTwo = table.createRow(); XWPFTableCell cell = tableRowTwo.getCell(0); XWPFParagraph personalInfo = cell.getParagraphs().get(0); XWPFRun r2 = personalInfo.createRun(); r2.setText("Name"); r2.addTab(); r2.addTab(); r2.setText(": " + polygraph.getName()); r2.addBreak(); r2.setText("Gender"); r2.addTab(); r2.addTab(); r2.setText(": " + polygraph.getGender()); r2.addBreak(); r2.setText("Age"); r2.addTab(); r2.addTab(); r2.setText(": " + polygraph.getAge()); r2.addBreak(); r2.setText("Date of Birth"); r2.addTab(); r2.setText(": " + polygraph.getBirthdate()); r2.addBreak(); r2.setText("Civil Status"); r2.addTab(); r2.setText(": " + polygraph.getCivilStatus()); r2.addBreak(); r2.setText("ID Presented"); r2.addTab(); r2.setText(": " + polygraph.getIdPresented()); r2.addBreak(); r2.setText("Address"); r2.addTab(); r2.setText(": " + polygraph.getAddress()); //Adding the picture XWPFTableCell pictureCell = tableRowTwo.getCell(1); XWPFParagraph pictureHolder = pictureCell.getParagraphs().get(0); XWPFRun pictureRun = pictureHolder.createRun(); FileInputStream getPhoto = new FileInputStream(polygraph.getPhotoLocation()); FileInputStream getImage = new FileInputStream(polygraph.getPhotoLocation()); ImageInputStream imageInput = ImageIO.createImageInputStream(getPhoto); BufferedImage bi = ImageIO.read(imageInput); pictureHolder.setAlignment(ParagraphAlignment.RIGHT); pictureRun.addPicture(getImage, XWPFDocument.PICTURE_TYPE_JPEG, null, Units.toEMU(120), Units.toEMU(120)); XWPFParagraph spacing = document.createParagraph(); XWPFRun spacingRun = spacing.createRun(); //create table XWPFTable otherTable = document.createTable(); //width CTTbl tableFixTwo = otherTable.getCTTbl(); CTTblPr prTwo = tableFixTwo.getTblPr(); CTTblWidth tblWTwo = prTwo.getTblW(); tblWTwo.setW(BigInteger.valueOf(4800)); tblWTwo.setType(STTblWidth.PCT); prTwo.setTblW(tblWTwo); tableFixTwo.setTblPr(prTwo); XWPFTableRow examInfoHeader = otherTable.createRow(); XWPFTableCell cellInfo = examInfoHeader.getCell(0); XWPFParagraph examInfo = cellInfo.getParagraphs().get(0); XWPFRun r3 = examInfo.createRun(); cellInfo.setColor("CDCDB4"); r3.setText("EXAM INFORMATION"); examInfo.setAlignment(ParagraphAlignment.CENTER); XWPFTableRow examInfoRow = otherTable.createRow(); XWPFTableCell cellRowInfo = examInfoRow.getCell(0); XWPFParagraph examInfoRowP = cellRowInfo.getParagraphs().get(0); XWPFRun examRun = examInfoRowP.createRun(); examRun.setText("Case Number"); examRun.addTab(); examRun.addTab(); examRun.setText(": " + polygraph.getCaseNo()); examRun.addBreak(); examRun.setText("Requesting Party"); examRun.addTab(); examRun.setText(": " + polygraph.getRequestingParty()); examRun.addBreak(); examRun.setText("Time/Date Received"); examRun.addTab(); examRun.setText(": " + polygraph.getTimeDateReceived()); examRun.addBreak(); examRun.setText("Nature of Case"); examRun.addTab(); examRun.addTab(); examRun.setText(": " + polygraph.getNatureOfCase()); examRun.addBreak(); examRun.setText("Exam Location"); examRun.addTab(); examRun.addTab(); examRun.setText(": " + polygraph.getExamLocation()); examRun.addBreak(); examRun.setText("Exam Date"); examRun.addTab(); examRun.addTab(); examRun.setText(": " + polygraph.getExamDate()); otherTable.removeRow(0); XWPFParagraph purposeOfExamination = document.createParagraph(); XWPFRun r4 = purposeOfExamination.createRun(); r4.setUnderline(UnderlinePatterns.SINGLE); r4.addBreak(); r4.setText("SECTION 1: PURPOSE OF EXAMINATION"); r4.addTab(); r4.addTab(); r4.addTab(); r4.addTab(); r4.addTab(); r4.addTab(); r4.addTab(); r4.addTab(); r4.addTab(); XWPFParagraph purposeOfExaminationContents = document.createParagraph(); XWPFRun r4Contents = purposeOfExaminationContents.createRun(); r4Contents.setText(polygraph.getPurpose()); XWPFParagraph preTestInterview = document.createParagraph(); XWPFRun r5 = preTestInterview.createRun(); r5.setUnderline(UnderlinePatterns.SINGLE); r5.setText("SECTION 2: PRE-TEST INTERVIEW"); r5.addTab(); r5.addTab(); r5.addTab(); r5.addTab(); r5.addTab(); r5.addTab(); r5.addTab(); r5.addTab(); r5.addTab(); XWPFParagraph preTestInterviewContents = document.createParagraph(); XWPFRun r5Contents = preTestInterviewContents.createRun(); r5Contents.setText(polygraph.getPreTest()); XWPFParagraph inTestPhase = document.createParagraph(); XWPFRun r6 = inTestPhase.createRun(); r6.setUnderline(UnderlinePatterns.SINGLE); r6.setText("SECTION 3: IN-TEST PHASE"); r6.addTab(); r6.addTab(); r6.addTab(); r6.addTab(); r6.addTab(); r6.addTab(); r6.addTab(); r6.addTab(); r6.addTab(); r6.addTab(); XWPFParagraph inTestPhaseContents = document.createParagraph(); XWPFRun r6Contents = inTestPhaseContents.createRun(); r6Contents.setText(polygraph.getInTest()); XWPFParagraph result = document.createParagraph(); XWPFRun r7 = result.createRun(); r7.setUnderline(UnderlinePatterns.SINGLE); r7.setText("SECTION 4: RESULT"); r7.addTab(); r7.addTab(); r7.addTab(); r7.addTab(); r7.addTab(); r7.addTab(); r7.addTab(); r7.addTab(); r7.addTab(); r7.addTab(); r7.addTab(); XWPFParagraph resultContents = document.createParagraph(); XWPFRun r7Contents = resultContents.createRun(); r7Contents.setText(polygraph.getResult()); XWPFParagraph postTestInterview = document.createParagraph(); XWPFRun r8 = postTestInterview.createRun(); r8.setUnderline(UnderlinePatterns.SINGLE); r8.setText("SECTION 5: POST-TEST INTERVIEW"); r8.addTab(); r8.addTab(); r8.addTab(); r8.addTab(); r8.addTab(); r8.addTab(); r8.addTab(); r8.addTab(); r8.addTab(); XWPFParagraph postTestInterviewContents = document.createParagraph(); XWPFRun r8Contents = postTestInterviewContents.createRun(); r8Contents.setText(polygraph.getPostTest()); XWPFParagraph remarks = document.createParagraph(); XWPFRun r9 = remarks.createRun(); r9.setUnderline(UnderlinePatterns.SINGLE); r9.setText("REMARKS:"); r9.addTab(); r9.addTab(); r9.addTab(); r9.addTab(); r9.addTab(); r9.addTab(); r9.addTab(); r9.addTab(); r9.addTab(); r9.addTab(); r9.addTab(); r9.addTab(); XWPFParagraph remarksContents = document.createParagraph(); XWPFRun r9Contents = remarksContents.createRun(); r9Contents.setText(polygraph.getRemarks()); XWPFParagraph timeDateCompleted = document.createParagraph(); XWPFRun r10 = timeDateCompleted.createRun(); r10.setUnderline(UnderlinePatterns.SINGLE); r10.setText("TIME AND DATE COMPLETED:"); r10.addTab(); r10.addTab(); r10.addTab(); r10.addTab(); r10.addTab(); r10.addTab(); r10.addTab(); r10.addTab(); r10.addTab(); r10.addTab(); XWPFParagraph timeDateCompletedContents = document.createParagraph(); XWPFRun r10Contents = timeDateCompletedContents.createRun(); r10Contents.setText(polygraph.getTimeDateCompleted()); XWPFParagraph examinedBy = document.createParagraph(); XWPFRun r11 = examinedBy.createRun(); r11.setUnderline(UnderlinePatterns.SINGLE); r11.setText("EXAMINED BY:"); r11.addTab(); r11.addTab(); r11.addTab(); r11.addTab(); r11.addTab(); r11.addTab(); r11.addTab(); r11.addTab(); r11.addTab(); r11.addTab(); r11.addTab(); r11.addTab(); XWPFParagraph examinedByContents = document.createParagraph(); XWPFRun r11Contents = examinedByContents.createRun(); r11Contents.setText(polygraph.getExaminerName()); r11Contents.addBreak(); r11Contents.setText(polygraph.getExaminerRank()); r11Contents.addBreak(); r11Contents.setText(polygraph.getExaminerPosition()); XWPFParagraph approvedBy = document.createParagraph(); XWPFRun r12 = approvedBy.createRun(); r12.setUnderline(UnderlinePatterns.SINGLE); r12.setText("APPROVED BY:"); r12.addTab(); r12.addTab(); r12.addTab(); r12.addTab(); r12.addTab(); r12.addTab(); r12.addTab(); r12.addTab(); r12.addTab(); r12.addTab(); r12.addTab(); r12.addTab(); XWPFParagraph approvedByContents = document.createParagraph(); XWPFRun r12Contents = approvedByContents.createRun(); // r12Contents.setText(polygraph.getApprovedName()); // r12Contents.addBreak(); // r12Contents.setText(polygraph.getApprovedRank()); // r12Contents.addBreak(); // r12Contents.setText(polygraph.getApprovedPosition()); // r12Contents.addBreak(); XWPFParagraph notedBy = document.createParagraph(); XWPFRun r13 = notedBy.createRun(); r13.setUnderline(UnderlinePatterns.SINGLE); r13.setText("NOTED BY:"); r13.addTab(); r13.addTab(); r13.addTab(); r13.addTab(); r13.addTab(); r13.addTab(); r13.addTab(); r13.addTab(); r13.addTab(); r13.addTab(); r13.addTab(); r13.addTab(); XWPFParagraph notedByContents = document.createParagraph(); XWPFRun r13Contents = notedByContents.createRun(); r13Contents.setText(polygraph.getNotedName()); r13Contents.addBreak(); r13Contents.setText(polygraph.getNotedRank()); r13Contents.addBreak(); r13Contents.setText(polygraph.getNotedPosition()); r13Contents.addBreak(); table.setInsideVBorder(XWPFTable.XWPFBorderType.NIL, 0, 0, "white"); document.getXWPFDocument(); } catch (Exception e) { e.printStackTrace(); } return document; }
From source file:com.dexter.fms.mbean.FleetMBean.java
License:Open Source License
private void addHeaderCell(XWPFTableRow row, String text, boolean first) { XWPFParagraph tp = null;/*from w w w . j a v a 2 s . c om*/ if (first) tp = row.getCell(0).getParagraphs().get(0); else { tp = row.addNewTableCell().getParagraphs().get(0); } XWPFRun tpr = tp.createRun(); tpr.setBold(true); tpr.setItalic(true); tpr.setText(text); }
From source file:com.foc.vaadin.gui.layouts.validationLayout.FVValidationLayout.java
License:Apache License
private void createWordTable() { try {//from w ww . j ava 2s.c o m XWPFDocument document = new XWPFDocument(); // New 2x2 table XWPFTable tableOne = document.createTable(); XWPFTableRow tableOneRowOne = tableOne.getRow(0); tableOneRowOne.setRepeatHeader(true); tableOneRowOne.getCell(0).setText("Hello"); tableOneRowOne.addNewTableCell().setText("World"); XWPFTableRow tableOneRowTwo = tableOne.createRow(); tableOneRowTwo.getCell(0).setText("This is"); tableOneRowTwo.getCell(1).setText("a table"); for (int i = 1; i < 50; i++) { tableOneRowTwo = tableOne.createRow(); tableOneRowTwo.getCell(0).setText("row " + i + " tol 0 bla bla very long string"); tableOneRowTwo.getCell(1).setText("row " + i + " col 1"); } //Add a break between the tables document.createParagraph().createRun().addBreak(); // New 3x3 table XWPFTable tableTwo = document.createTable(); XWPFTableRow tableTwoRowOne = tableTwo.getRow(0); tableTwoRowOne.getCell(0).setText("col one, row one"); tableTwoRowOne.addNewTableCell().setText("col two, row one"); tableTwoRowOne.addNewTableCell().setText("col three, row one"); XWPFTableRow tableTwoRowTwo = tableTwo.createRow(); tableTwoRowTwo.getCell(0).setText("col one, row two"); tableTwoRowTwo.getCell(1).setText("col two, row two"); tableTwoRowTwo.getCell(2).setText("col three, row two"); XWPFTableRow tableTwoRowThree = tableTwo.createRow(); tableTwoRowThree.getCell(0).setText("col one, row three"); tableTwoRowThree.getCell(1).setText("col two, row three"); tableTwoRowThree.getCell(2).setText("col three, row three"); FileOutputStream outStream = new FileOutputStream( "C://Users//user//Desktop//POI Word Doc Sample Table 1.docx"); document.write(outStream); outStream.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.foc.vaadin.gui.mswordGenerator.FocMSWordTable.java
License:Apache License
private void addCell(XWPFTableRow row, int columnIndex, String content, boolean isTitleRow) { XWPFTableCell cell = null;/*from w ww . java 2 s . co m*/ if (row.getCell(columnIndex) == null) { cell = row.addNewTableCell(); cell.setText(content); } else { cell = row.getCell(columnIndex); cell.setText(content); } if (isTitleRow) { cell.setColor("838b83"); } }
From source file:com.min.word.core.MakeWordFileTest.java
License:Apache License
public static void main(String[] args) throws Exception { String fileName = "test.docx"; System.out.println("---------- Word Create Start ------------"); // word ? ?/* w w w.ja va 2s. c om*/ XWPFDocument document = new XWPFDocument(); FileOutputStream out = new FileOutputStream(new File(fileName)); System.out.println("---------- Create Blank Success ------------"); //Paragraph ? XWPFParagraph paragraph = document.createParagraph(); System.out.println("---------- Create Paragraph Success ------------"); //border ? paragraph.setBorderBottom(Borders.BASIC_BLACK_DASHES); paragraph.setBorderLeft(Borders.BASIC_BLACK_DASHES); paragraph.setBorderRight(Borders.BASIC_BLACK_DASHES); paragraph.setBorderTop(Borders.BASIC_BLACK_DASHES); System.out.println("---------- Create Border Success ------------"); XWPFRun run = paragraph.createRun(); run.setText("At tutorialspoint.com, we strive hard to " + "provide quality tutorials for self-learning " + "purpose in the domains of Academics, Information " + "Technology, Management and Computer Programming Languages."); System.out.println("---------- Text Write to File ------------"); //Table ? XWPFTable table = document.createTable(); //row XWPFTableRow rowOne = table.getRow(0); rowOne.getCell(0).setText("Col One, Row One"); rowOne.addNewTableCell().setText("Col Tow, Row One"); rowOne.addNewTableCell().setText("Col Three, Row One"); //row XWPFTableRow rowTow = table.createRow(); rowTow.getCell(0).setText("Col One, Row Tow"); rowTow.getCell(1).setText("Col Tow, Row Tow"); rowTow.getCell(2).setText("Col Three, Row Tow"); //row XWPFTableRow rowThree = table.createRow(); rowThree.getCell(0).setText("Col One, Row Three"); rowThree.getCell(1).setText("Col Tow, Row Three"); rowThree.getCell(2).setText("Col Three, Row Three"); System.out.println("---------- Create Table Success ------------"); //Add Image XWPFParagraph imageParagraph = document.createParagraph(); XWPFRun imageRun = imageParagraph.createRun(); imageRun.addPicture(new FileInputStream("test.png"), XWPFDocument.PICTURE_TYPE_PNG, "test.png", Units.toEMU(300), Units.toEMU(300)); System.out.println("---------- Create Image Success ------------"); //Hyperlink XWPFParagraph hyperlink = document.createParagraph(); String id = hyperlink.getDocument().getPackagePart() .addExternalRelationship("http://niee.kr", XWPFRelation.HYPERLINK.getRelation()).getId(); CTR ctr = CTR.Factory.newInstance(); CTHyperlink ctHyperlink = hyperlink.getCTP().addNewHyperlink(); ctHyperlink.setId(id); CTText ctText = CTText.Factory.newInstance(); ctText.setStringValue("Hyper-Link TEST"); ctr.setTArray(new CTText[] { ctText }); // ???? ? CTColor color = CTColor.Factory.newInstance(); color.setVal("0000FF"); CTRPr ctrPr = ctr.addNewRPr(); ctrPr.setColor(color); ctrPr.addNewU().setVal(STUnderline.SINGLE); // CTFonts fonts = ctrPr.isSetRFonts() ? ctrPr.getRFonts() : ctrPr.addNewRFonts(); fonts.setAscii("?? "); fonts.setEastAsia("?? "); fonts.setHAnsi("?? "); // ? CTHpsMeasure sz = ctrPr.isSetSz() ? ctrPr.getSz() : ctrPr.addNewSz(); sz.setVal(new BigInteger("24")); ctHyperlink.setRArray(new CTR[] { ctr }); hyperlink.setAlignment(ParagraphAlignment.LEFT); hyperlink.setVerticalAlignment(TextAlignment.CENTER); System.out.println("---------- Create Hyperlink Success ------------"); //Font style XWPFParagraph fontStyle = document.createParagraph(); //set Bold an Italic XWPFRun boldAnItalic = fontStyle.createRun(); boldAnItalic.setBold(true); boldAnItalic.setItalic(true); boldAnItalic.setText("Bold an Italic"); boldAnItalic.addBreak(); //set Text Position XWPFRun textPosition = fontStyle.createRun(); textPosition.setText("Set Text Position"); textPosition.setTextPosition(100); //Set Strike through and font Size and Subscript XWPFRun otherStyle = fontStyle.createRun(); otherStyle.setStrike(true); otherStyle.setFontSize(20); otherStyle.setSubscript(VerticalAlign.SUBSCRIPT); otherStyle.setText(" Set Strike through and font Size and Subscript"); System.out.println("---------- Set Font Style ------------"); //Set Alignment Paragraph XWPFParagraph alignment = document.createParagraph(); //Alignment to Right alignment.setAlignment(ParagraphAlignment.RIGHT); XWPFRun alignRight = alignment.createRun(); alignRight.setText( "At tutorialspoint.com, we strive hard to " + "provide quality tutorials for self-learning " + "purpose in the domains of Academics, Information " + "Technology, Management and Computer Programming " + "Languages."); //Alignment to Center alignment = document.createParagraph(); //Alignment to Right alignment.setAlignment(ParagraphAlignment.CENTER); XWPFRun alignCenter = alignment.createRun(); alignCenter.setText("The endeavour started by Mohtashim, an AMU " + "alumni, who is the founder and the managing director " + "of Tutorials Point (I) Pvt. Ltd. He came up with the " + "website tutorialspoint.com in year 2006 with the help" + "of handpicked freelancers, with an array of tutorials" + " for computer programming languages. "); System.out.println("---------- Set Alignment ------------"); //word ? document.write(out); out.close(); System.out.println("---------- Save File Name : " + fileName + " ------------"); System.out.println("---------- Word Create End ------------"); }
From source file:csv2docxconverter.DocumentGenerator.java
/** * Create header for a table/*w ww . j av a 2 s. co m*/ */ private void setHeader(XWPFTable table, String[] columnNames) { // set initial cell XWPFTableRow tableRowOne = table.getRow(0); // add other cells for (int i = 0; i < columnNames.length; i++) { XWPFTableCell cell; if (i == 0) { cell = tableRowOne.getCell(0); } else { cell = tableRowOne.addNewTableCell(); } XWPFRun run = setHeaderCell(cell); run.setText(columnNames[i]); } }
From source file:de.micromata.tpsb.doc.renderer.MicrosoftWordRenderer.java
License:Apache License
/** * Fgt einzele Tests aus einem Test-Case hinzu * // w w w.j ava 2 s . c om * @param fInfo the file information */ private void addTestMethods(FileInfo fInfo) { for (MethodInfo mInfo : fInfo.getMethodInfos()) { addH2(mInfo.getMethodName()); // Java-Doc Test-Methode if (mInfo.getJavaDocInfo() != null && mInfo.getJavaDocInfo().getTitle() != null) { addPar("Testbeschreibung", mInfo.getJavaDocInfo().getTitle()); } // Autoren if (mInfo.getJavaDocInfo() != null && mInfo.getJavaDocInfo().getTagInfo("@author") != null && mInfo.getJavaDocInfo().getTagInfo("@author").isEmpty() == false) { List<String> authors = new ArrayList<String>(); for (Pair<String, String> author : mInfo.getJavaDocInfo().getTagInfo("@author")) { authors.add(author.getSecond()); } addPar("Autoren Tests", authors.toArray(new String[authors.size()])); } addPar("Testablauf", mInfo.getTestSteps().size() == 0 ? "Keine Daten" : ""); // Parameter in neue Zeilen hinzufgen XWPFTable testStepTable = document.createTable(); setTableStyle(testStepTable, "TabelleProfessionell"); XWPFTableRow headRow = testStepTable.getRow(0); headRow.getCell(0).setText("#"); headRow.addNewTableCell().setText("Vorgehen"); for (TestStepInfo tInfo : mInfo.getTestSteps()) { XWPFTableRow row = testStepTable.createRow(); setColor("EDEDED", row.getCell(0).getCTTc()); // graue steps setColor("EDEDED", row.getCell(1).getCTTc()); row.getCell(0).setText("#" + tInfo.getTestStep()); if (tInfo.getTbJavaDocInfo() != null) { row.getCell(1).setText(tInfo.getTbJavaDocInfo().getTitle()); } else { row.getCell(1).setText("Keine Daten"); } // Aufrufparameter if (tInfo.getParameters() != null && tInfo.getParameters().isEmpty() == false) { for (ParameterInfo pInfo : tInfo.getParameters()) { XWPFTableRow pRow = testStepTable.createRow(); XWPFParagraph p = pRow.getCell(1).getParagraphs().get(0); XWPFRun pRun = p.createRun(); pRun.setText(pInfo.getJavaDoc() + ": " + pInfo.getParamValue()); pRow.getCell(1).addParagraph(p); } } } // Falls vorhanden auch Screenshots in die Doku aufnehmen addScreenShotsIfExists(mInfo); } }
From source file:MainPackage.Controllers.OrderController.java
public void Print(Frame frame, Orders order, Account _account) { try {//from w ww .ja v a 2 s .c o m XWPFDocument document = new XWPFDocument(); File file = new File("Ha n " + order.getIdCode() + ".doc"); if (file.exists()) { file.createNewFile(); } FileOutputStream out = new FileOutputStream(file); XWPFParagraph paragraph = document.createParagraph(); paragraph.setAlignment(ParagraphAlignment.CENTER); XWPFRun run; // BookViewModel bookView = new BookViewModel(book); ///////////////// run = createFieldRun(paragraph, "CHI TIT HA ?N"); run.setFontSize(24); paragraph = createPrintInformation(document, _account); paragraph = createBookProductInformation(document, order); paragraph = createBookInformation(document, order); //create table XWPFTable table = document.createTable(); setTableAlignment(table, STJc.CENTER); table.setCellMargins(50, 50, 50, 50); table.setInsideHBorder(XWPFTable.XWPFBorderType.SINGLE, 10, 10, ""); table.setInsideVBorder(XWPFTable.XWPFBorderType.NONE, 20, 20, ""); //create first row XWPFTableRow row = table.getRow(0); row.setHeight(40); row.getCell(0).setText("STT"); row.addNewTableCell().setText("M Sn phm"); row.addNewTableCell().setText("Tn Sn phm"); row.addNewTableCell().setText("?n v"); row.addNewTableCell().setText("S lng"); row.addNewTableCell().setText("Gi ti?n"); row.addNewTableCell().setText("Thnh ti?n"); List<OrderLine> list = (List<OrderLine>) order.getOrderLineCollection(); for (int i = 0; i < list.size(); i++) { OrderLine line = list.get(i); row = table.createRow(); row.getCell(0).setText((i + 1) + ""); row.getCell(1).setText(line.getProductId().getIdCode()); row.getCell(2).setText(line.getProductId().getName()); row.getCell(3).setText("Quyn "); row.getCell(4).setText(line.getQuantity() + " "); row.getCell(5).setText(IntToVND(line.getUnitPrice()) + " "); row.getCell(6).setText(IntToVND(line.getTotalPrice()) + " "); } document.write(out); out.close(); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(file); } JOptionPane .showMessageDialog(frame, "Xut file " + file.getName() + " thnh cng" + '\n' + "Ti v tr: " + file.getAbsolutePath(), "In thng tin Ha n", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(frame, "Xut file tht bi." + '\n' + "Vui lng ng ca s ang s dng file", "In thng tin Ha n", JOptionPane.WARNING_MESSAGE); } }
From source file:org.obeonetwork.m2doc.generator.TableClientProcessor.java
License:Open Source License
/** * Fill a newly created word table with the data from an MTable. * /*from ww w. ja v a 2 s.co m*/ * @param table * The newly created word table * @param mtable * The MTable that describes the data and styles to insert */ private void fillTable(XWPFTable table, MTable mtable) { XWPFTableRow headerRow = table.getRow(0); initializeEmptyTableCell(headerRow.getCell(0), null, null); Iterable<? extends MColumn> mcolumns = mtable.getColumns(); for (MColumn mcol : mcolumns) { XWPFTableCell cell; cell = headerRow.addNewTableCell(); initializeEmptyTableCell(cell, null, null); setCellContent(cell, mcol.getLabel(), null); } for (MRow mrow : mtable.getRows()) { XWPFTableRow row = table.createRow(); List<XWPFTableCell> cells = row.getTableCells(); for (int i = 0; i < cells.size(); i++) { XWPFTableCell cell = cells.get(i); // Make sure empty cells are empty and have the right style if (i > 0) { initializeEmptyTableCell(cell, mrow, Iterables.get(mtable.getColumns(), i - 1)); } else { initializeEmptyTableCell(cell, null, null); } } XWPFTableCell cell0 = row.getCell(0); setCellContent(cell0, mrow.getLabel(), null); for (MCell mcell : mrow.getCells()) { MColumn mcol = mcell.getColumn(); if (mcol != null) { XWPFTableCell cell = row.getCell(Iterables.indexOf(mcolumns, Predicates.equalTo(mcol)) + 1); setCellContent(cell, mcell.getLabel(), mcell.getStyle()); } } } }