- Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"><w:body><w:p w:rsidR="005517ED" w:rsidRDefault="00B076EB"><w:r><w:t xml:space="preserve">Testing </w:t></w:r><w:r w:rsidR="00214F89"><w:rPr><w:noProof/></w:rPr><w:drawing><wp:inline distT="0" distB="0" distL="0" distR="0"><wp:extent cx="5486400" cy="3200400"/><wp:effectExtent l="19050" t="0" r="19050" b="0"/><wp:docPr id="1" name="Chart 1"/><wp:cNvGraphicFramePr/><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart"><c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId4"/></a:graphicData></a:graphic></wp:inline></w:drawing></w:r></w:p><w:sectPr w:rsidR="005517ED" w:rsidSect="00B66653"><w:pgSz w:w="12240" w:h="15840"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/><w:cols w:space="720"/><w:docGrid w:linePitch="360"/></w:sectPr></w:body></w:document>
I used this code - i wanted to generate a document similar to the above document.
- Code: Select all
String stringForChart = "<w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" w:rsidR=\"005517ED\" w:rsidRDefault=\"00B076EB\">";
stringForChart = stringForChart + "<w:r>";
stringForChart = stringForChart + "<w:t xml:space=\"preserve\">Testing </w:t>";
stringForChart = stringForChart + "</w:r>";
stringForChart = stringForChart + "<w:r xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" w:rsidR=\"00214F89\">";
stringForChart = stringForChart + "<w:rPr>";
stringForChart = stringForChart + "<w:noProof/>";
stringForChart = stringForChart + "</w:rPr>";
stringForChart = stringForChart + "<w:drawing>";
stringForChart = stringForChart + "<wp:inline distT=\"0\" distB=\"0\" distL=\"0\" distR=\"0\">";
stringForChart = stringForChart + "<wp:extent cx=\"5486400\" cy=\"3200400\"/><wp:effectExtent l=\"19050\" t=\"0\" r=\"19050\" b=\"0\"/>";
stringForChart = stringForChart + "<wp:docPr id=\"1\" name=\"Chart 1\"/>";
stringForChart = stringForChart + "<wp:cNvGraphicFramePr/>";
stringForChart = stringForChart + "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">";
stringForChart = stringForChart + "<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/chart\">";
stringForChart = stringForChart + "<c:chart xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" ";
stringForChart = stringForChart + "xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" ";
stringForChart = stringForChart + "r:id=\"rId4\"/>";
stringForChart = stringForChart + "</a:graphicData>";
stringForChart = stringForChart + "</a:graphic>";
stringForChart = stringForChart + "</wp:inline>";
stringForChart = stringForChart + "</w:drawing>";
stringForChart = stringForChart + "</w:r>";
stringForChart = stringForChart + "</w:p>";
wordMLPackage.getMainDocumentPart().addObject(
org.docx4j.XmlUtils.unmarshalString(stringForChart) );
My issue is that the code works fine and generates a docx file. When I open the file using Microsoft word it says that its corrupted , in open office I cannot see the chart which I was intending to create. If I add other objects like paragraphs and tables I am able to see them but not this chart. Can you help me with it?