如何通过Java代码向Word文档添加文档属性
在Java中使用Apache POI可以操作Microsoft Office文件,包括Word、Excel、PowerPoint等文件。 下面是一个示例代码,展示如何向Word文档添加文档属性:
import java.io.FileOutputStream;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;
public class WordDocProperty {
public static void main(String[] args) throws Exception {
String fileName = "D:/sample.doc";
HWPFDocument doc = new HWPFDocument();
Range range = doc.getRange();
FileOutputStream out = new FileOutputStream(fileName);
SummaryInformation summaryInformation = PropertySetFactory.newSummaryInformation();
summaryInformation.setTitle("Sample Document"<