In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the method of Java adding, reading, and deleting Excel document properties?" in the actual case of the operation process, many people will encounter such a dilemma, then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
Use tools: Spire.XLS for Java
How to get it: download the package through the official website. After downloading, extract the file and import the jar file in the lib folder into the java program, or download and import it through the Maven repository. The import effect of Jar is as follows:
Java code example
[example 1] add Excel document properties
Import com.spire.xls.*; import java.util.Date; public class AddProperties {public static void main (String [] args) {/ / load Excel document Workbook wb = new Workbook (); wb.loadFromFile ("input.xlsx"); / / set built-in document properties such as title, theme, author, etc. Wb.getDocumentProperties (). SetTitle ("set document properties") Wb.getDocumentProperties (). SetSubject ("category A"); wb.getDocumentProperties (). SetAuthor ("Bubble"); wb.getDocumentProperties (). SetManager ("July"); wb.getDocumentProperties (). SetCompany ("Alibaba"); wb.getDocumentProperties (). SetCategory ("internal"); wb.getDocumentProperties (). SetKeywords ("document, draft") / / add custom document properties wb.getCustomDocumentProperties (). Add ("_ MarkAsFinal", true); wb.getCustomDocumentProperties (). Add ("edit", "Administrator"); wb.getCustomDocumentProperties (). Add ("contact phone", 12345678); wb.getCustomDocumentProperties (). Add ("update date", new Date ()) / / Save the result document wb.saveToFile ("AddProperties.xlsx", ExcelVersion.Version2010); wb.dispose ();}}
The generated document can see the effect of property addition.
[example 2] read Excel document properties
Import com.spire.xls.*; public class ReadProperties {public static void main (String [] args) {/ / load Excel document Workbook wb = new Workbook (); wb.loadFromFile ("AddProperties.xlsx"); / / get Excel built-in document property System.out.println ("title:" + wb.getDocumentProperties () .getTitle ()) System.out.println ("theme:" + wb.getDocumentProperties (). GetSubject ()); System.out.println ("author:" + wb.getDocumentProperties (). GetAuthor ()); System.out.println ("Unit:" + wb.getDocumentProperties (). GetCompany ()); System.out.println ("Supervisor:" + wb.getDocumentProperties (). GetManager ()) System.out.println ("category:" + wb.getDocumentProperties () .getCategory ()); System.out.println ("keyword:" + wb.getDocumentProperties () .getKeywords ()); / / get Excel custom document properties DocumentProperty property = (DocumentProperty) wb.getCustomDocumentProperties () .get (0) / / read the name and value of the first custom document property System.out.println ("name:" + property.getName ()); System.out.println ("value:" + property.getValue ());}}
The result of reading the document properties:
[example 3] Delete Excel document properties
Import com.spire.xls.*; public class RemoveProperties {public static void main (String [] args) {/ / load Excel document Workbook wb = new Workbook (); wb.loadFromFile ("AddProperties.xlsx"); / / remove the built-in property wb.getDocumentProperties () .setTitle ("); wb.getDocumentProperties () .setSubject (") by setting the value of the corresponding document property to null. Wb.getDocumentProperties (). SetAuthor ("); wb.getDocumentProperties (). SetCompany ("); wb.getDocumentProperties (). SetManager ("); wb.getDocumentProperties (). SetCategory ("); wb.getDocumentProperties (). SetKeywords ("); wb.getDocumentProperties (). SetComments (") / / remove the custom document property wb.getCustomDocumentProperties (). Remove ("edit"); wb.getCustomDocumentProperties (). Remove ("contact phone") based on the name of the custom document property; / / Save the document wb.saveToFile ("RemoveProperties.xlsx", ExcelVersion.Version2010); wb.dispose ();}}
The generated document can see the effect of property deletion.
This is the end of the content of "what is the method for Java to add, read and delete Excel document properties". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.