using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using DSOFile;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
//注册
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "regsvr32";
p.StartInfo.Arguments = "DSOFile.dll";
p.Start();
p.WaitForExit();
p.Close();
p.Dispose();
//写入
string path = "c:/Book1.xlsx";
DSOFile.OleDocumentProperties dso = new DSOFile.OleDocumentProperties();
dso.Open(path, false, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
dso.SummaryProperties.Title = "This is the Title";
dso.SummaryProperties.Subject = "This is the Subject";
dso.SummaryProperties.Company = "RTDev";
dso.SummaryProperties.Author = "Ron T.";
dso.Save();
//读取
Console.WriteLine(dso.SummaryProperties.Title);
Console.WriteLine(dso.SummaryProperties.Subject);
Console.WriteLine(dso.SummaryProperties.Company);
Console.WriteLine(dso.SummaryProperties.Author);
dso.Close(false);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}
需要将dsofile.dll文件复制到debug目录下,再在项目里引用。
dsofile.dll属于com组件,需要注册。