我正在编写一个关于女巫用户必须添加报告(Word 文档)并可以查看它们的网站,我将 *.doc 转换为 *.pdf,然后通过 pdf.js 显示它们。对于转换,我使用 Microsoft.Office.Interop.Word。代码看起来像
public void ConvertDocument(string PATH)
{
FileInfo FILE = new FileInfo(PATH);
if (FILE.Extension.ToLower() == ".doc" || FILE.Extension.ToLower() == ".docx" || FILE.Extension.ToLower() == ".docm" || FILE.Extension.ToLower() == ".dotx" || FILE.Extension.ToLower() == ".dotm")
{
if (FILE.Length == 0)
{
return;
}
object oMissing = System.Reflection.Missing.Value;
Word.Application word = new Word.Application();
try
{
word.Visible = false;
word.ScreenUpdating = false;
Object filename = (Object)FILE.FullName;
Word.Document doc = word.Documents.Open(ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
try
{
doc.Activate();
object outputFileName = FILE.FullName.Replace(FILE.Extension, ".PDF");
doc.SaveAs(ref outputFileName, Word.WdSaveFormat.wdFormatPDF, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
finally
{
object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
((Word._Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
doc = null;
}
}
finally
{
((Word._Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
word = null;
}
File.Delete(PATH);
}
}
- 那安全吗?
- 它会处理多少用户?
- 它需要什么资源?
- 我应该在服务器上安装 MS Office 来运行网站吗?
- 这实际上是一个好方法吗?