C# 添加、读取、删除Excel文档属性

C# 添加、读取、删除Excel文档属性,第1张

概述在文档属性中,可以设置诸多关于文档的信息,如创建时间、作者、单位、类别、关键词、备注等摘要信息以及一些自定义的文档属性。下面将通过C#程序来演示如何设置,同时对文档内的已有信息,也可以实现读取删除

在文档属性中,可以设置诸多关于文档的信息,如创建时间、作者、单位、类别、关键词、备注等摘要信息以及一些自定义的文档属性。下面将通过C#程序来演示如何设置,同时对文档内的已有信息,也可以实现读取或删除等 *** 作。

示例大纲:

1. 添加文档属性

  1.1 添加摘要信息

  1.2 添加自定义文档信息

2. 读取文档属性

3. 删除文档信息

  3.1 删除所有摘要信息、自定义文档属性

  3.2 删除指定摘要信息、自定义文档属性

 

使用工具:Spire.XLS for .NET pack

获取方法1:通过官网下载包。下载后,解压文件,安装Bin文件夹下的程序。安装后,将安装路径下Bin文件夹下的Spire.Xls.dll文件添加引用至vs项目程序。如下所示:

 

 

获取方法2:可通过Nuget下载。

 

C# 示例【示例】添加文档属性
using Spire.Xls; System;namespace AddPropertIEs{    class Program    {        static voID Main(string[] args)        {            //加载Excel文档            Workbook workbook = new Workbook();            workbook.LoadFromfile("test.xlsx");            设置摘要            workbook.documentPropertIEs.Author = Mara;            workbook.documentPropertIEs.Title = 摘要;            workbook.documentPropertIEs.Keywords = 摘要,属性;            workbook.documentPropertIEs.category = 展示文档;            workbook.documentPropertIEs.Company = 冰蓝科技;            workbook.documentPropertIEs.Comments = 请勿修改;            workbook.documentPropertIEs.Subject = 测试;            workbook.documentPropertIEs.Manager = Tom;            设置自定义属性            workbook.CustomdocumentPropertIEs.Add(_MarkAsFinal",true);            workbook.CustomdocumentPropertIEs.Add(联系电话81705109更新时间,DateTime.Now);            保存文档            workbook.Savetofile(AddPropertIEs.xlsx

 

【示例2】读取文档信息
 Spire.Xls.Collections; Spire.Xls.Core; ReadPropertIEs{    加载Excel文档            Workbook wb =  Workbook();            wb.LoadFromfile(获取文档属性            Console.Writeline(摘要信息:);            Console.Writeline(标题: " + wb.documentPropertIEs.Title);            Console.Writeline(主题:  wb.documentPropertIEs.Subject);            Console.Writeline(作者:  wb.documentPropertIEs.Author);            Console.Writeline(管理者:  wb.documentPropertIEs.Manager);            Console.Writeline(公司:  wb.documentPropertIEs.Company);            Console.Writeline(类别:  wb.documentPropertIEs.category);            Console.Writeline(关键字:  wb.documentPropertIEs.Keywords);            Console.Writeline(备注:  wb.documentPropertIEs.Comments);            获取自定义属性            Console.Writeline(\n自定义属性:);            for (int i = 0; i < wb.CustomdocumentPropertIEs.Count; i++)            {                Console.Writeline(wb.CustomdocumentPropertIEs[i].name + :  wb.CustomdocumentPropertIEs[i].Value);            }            Console.Read();        }    }}

文档属性读取结果:

 

 

【示例3】删除文档属性
 Spire.Xls; DeletePropertIEs{    加载工作簿            Workbook workbook = 删除摘要及自定义文档属性            workbook.documentPropertIEs.Clear();删除所有摘要信息            workbook.CustomdocumentPropertIEs.Clear();删除所有自定义文档属性                        DeletePropertIEs.xlsx/*//删除指定摘要及自定义文档属性            workbook.documentPropertIEs.Author = "";//设置指定摘要信息为空,删除摘要内容            workbook.CustomdocumentPropertIEs.Remove("联系电话");//删除指定名称的自定义文档属性            workbook.Savetofile("DeleteCustomdocumentPropertIEs.xlsx",fileFormat.Version2013);*/        }    }}

文档属性删除结果:

 

(本文完)

 

总结

以上是内存溢出为你收集整理的C# 添加、读取、删除Excel文档属性全部内容,希望文章能够帮你解决C# 添加、读取、删除Excel文档属性所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1213617.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-04
下一篇2022-06-04

发表评论

登录后才能评论

评论列表(0条)

    保存