在C#.Net中使用OpenXML SpreadsheetDocument类创建电子表格时,Authors和Last saved by字段被设置为"James Westgate“。
如何清除或覆盖James的名字?
SpreadsheetDocument doc = SpreadsheetDocument.Open(stream, true);
doc.PackageProperties.Creator = "sh";
...is对我不起作用
更新:-
using System;
using System.Windows.Forms;
using System.IO;
using DocumentFormat.OpenXml.Extensions;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
namespace OpenXMLProps
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public MemoryStream Execute()
{
MemoryStream stream = SpreadsheetReader.Create();
using (SpreadsheetDocument doc = SpreadsheetDocument.Open(stream, true))
{
WorksheetPart worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1");
WorksheetWriter writer = new WorksheetWriter(doc, worksheetPart);
doc.PackageProperties.Creator = "Finbar mahoolahan";
SpreadsheetWriter.Save(doc);
return new MemoryStream(stream.ToArray());
}
}
private void button1_Click(object sender, EventArgs e)
{
using (FileStream fs = new FileStream("excel_test.xlsx", FileMode.Create, FileAccess.Write))
{
MemoryStream excel_stream = Execute();
excel_stream.WriteTo(fs);
}
}
}
}
发布于 2018-07-28 06:33:20
这对我很有效(在OpenXml包中添加完NuGet之后):
using (var doc = SpreadsheetDocument.Open(@"C:\tmp\MyExcelFile.xlsx", true))
{
var props = doc.PackageProperties;
props.Creator = "Flydog57";
props.LastModifiedBy = "Flydog57";
doc.Save();
}
它甚至在我第一次尝试的时候就起作用了!这是一件不寻常的事情。
https://stackoverflow.com/questions/51561363
复制相似问题