作者:KenNaNa | 来源:互联网 | 2023-02-04 18:22
MetaData Excel
预期的文件属性
需要使用Apache POI将自定义数据写入excel文件。我正在使用POI 3.1.1版本jar。这是我的代码:
FileInputStream fis = new FileInputStream(sample);
workbook = new XSSFWorkbook(fis);
POIXMLProperties props = workbook.getProperties();
/* Let us set some core properties now*/
POIXMLProperties.CoreProperties coreProp = props.getCoreProperties();
coreProp.setCreator("Thinktibits"); //set document creator
coreProp.setDescription("set Metadata using Apache POI / Java");
coreProp.setCategory("Programming"); //category
/* Finally, we can set some custom Properies */
POIXMLProperties.CustomProperties custProp = props.getCustomProperties();
custProp.addProperty("Author", "Thinktibits");// String
custProp.addProperty("Year", 2014); // Number Property
custProp.addProperty("Published", true); //Yes No Property
custProp.addProperty("Typist", "tika");
FileOutputStream fos = new FileOutputStream(sample);
workbook.write(fos);
fos.close();
谁能帮助我在我的代码出问题的地方获得所需的自定义标签?
1> 小智..:
在这里,此代码适用于Excel 2011和XLSX(当然,xlsx不需要在EXCEL中打开):
public class ApachePOI {
public static void main(final String[] args) throws Exception {
FileInputStream fis = new FileInputStream("C:\\Mappe1.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(fis);
POIXMLProperties props = workbook.getProperties();
/* Let us set some core properties now */
POIXMLProperties.CoreProperties coreProp = props.getCoreProperties();
coreProp.setCreator("Thinktibits"); // set document creator
coreProp.setDescription("set Metadata using Apache POI / Java");
coreProp.setCategory("Programming"); // category
/* Finally, we can set some custom Properies */
POIXMLProperties.CustomProperties custProp = props.getCustomProperties();
custProp.addProperty("Author", "Thinktibits");// String
custProp.addProperty("Year", 2014); // Number Property
custProp.addProperty("Published", true); // Yes No Property
custProp.addProperty("Typist", "tika");
FileOutputStream fos = new FileOutputStream("C:\\Mappe1.xlsx");
workbook.write(fos);
fos.close();
}
}
作为依赖,我得到了:
org.apache.poi
poi
3.16
org.apache.poi
poi-ooxml
3.16