从打开时更新防止Word文档的领域 [英] Prevent Word document's fields from updating when opened
问题描述
我写了另一支球队是递归的文件夹去,并将其转换使用Word互操作与C#发现PDF中的Word文档的工具。
I wrote a utility for another team that recursively goes through folders and converts the Word docs found to PDF by using Word Interop with C#.
我们的问题其是,这些文件用日期字段更新到今天的日期,他们得到保存之前创建的。我发现了禁用的方法更新打印前场,但我需要防止从场更新开放。
The problem we're having is that the documents were created with date fields that update to today's date before they get saved out. I found a method to disable updating fields before printing, but I need to prevent the fields from updating on open.
这可能吗?我想这样做在C#中修复,但如果我必须做一个Word宏,我可以。
Is that possible? I'd like to do the fix in C#, but if I have to do a Word macro, I can.
推荐答案
好,我没有找到一个方法与互操作做到这一点,但我的公司确实买Aspose.Words和我写了一个实用程序将Word文档转换为TIFF图像。除非你明确告诉它的阅读Aspose 工具将不会更新的字段。以下是我与阅读Aspose使用的代码的样本。请记住,我不得不将Word文档转换成单页TIFF图像的要求,我硬编码了许多选项,因为它只是一个在这个项目上为自己实用。
Well, I didn't find a way to do it with Interop, but my company did buy Aspose.Words and I wrote a utility to convert the Word docs to TIFF images. The Aspose tool won't update fields unless you explicitly tell it to. Here's a sample of the code I used with Aspose. Keep in mind, I had a requirement to convert the Word docs to single page TIFF images and I hard-coded many of the options because it was just a utility for myself on this project.
private static bool ConvertWordToTiff(string inputFilePath, string outputFilePath)
{
try
{
Document doc = new Document(inputFilePath);
for (int i = 0; i < doc.PageCount; i++)
{
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
options.PageIndex = i;
options.PageCount = 1;
options.TiffCompression = TiffCompression.Lzw;
options.Resolution = 200;
options.ImageColorMode = ImageColorMode.BlackAndWhite;
var extension = Path.GetExtension(outputFilePath);
var pageNum = String.Format("-{0:000}", (i+1));
var outputPageFilePath = outputFilePath.Replace(extension, pageNum + extension);
doc.Save(outputPageFilePath, options);
}
return true;
}
catch (Exception ex)
{
LogError(ex);
return false;
}
}
这篇关于从打开时更新防止Word文档的领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!