I am probably being completely boneheaded here, but I feel like I'm going crazy and missing something obvious. Any help would be greatly appreciated.
![Smile :)](https://www.docx4java.org/forums/images/smilies/icon_e_smile.gif)
This is the code I have so far:
- Code: Select all
import java.io.File;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.exceptions.InvalidFormatException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart;
import com.entrocorp.docizer.Docizer;
public class Word {
public static void writeToFile(String internalPath, String content) {
File docxFile = new File(Docizer.instance.getRootDirectory() + File.separator + internalPath + ".docx");
try {
WordprocessingMLPackage file = WordprocessingMLPackage.load(docxFile);
file.getMainDocumentPart().getStyleDefinitionsPart().
file.getMainDocumentPart().addStyledParagraphOfText("DefaultParagraphFont", content);
file.save(docxFile);
} catch (Docx4JException e) {
e.printStackTrace();
}
}
public static void createFile(String internalPath) {
try {
WordprocessingMLPackage file = WordprocessingMLPackage.createPackage();
File docxFile = new File(Docizer.instance.getRootDirectory() + File.separator + internalPath + ".docx");
file.save(docxFile);
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (Docx4JException e) {
e.printStackTrace();
}
}
}