积极答复者
如何将office文件转换成图片格式

问题
答案
-
Hi sl_water,
欢迎来到MSDN论坛。
如果您只是想把office文档转成图片格式,可以使用现成的office工具,Microsoft Office Document Imaging (MODI)。
Office 2003 & 2007:http://office.microsoft.com/en-us/help/about-microsoft-office-document-imaging-HP001077103.aspx
Office 2010:http://support.microsoft.com/kb/982760
如果希望使用代码实现,您可以参考下面的代码:
static void Main(string[] args) { print(); Console.WriteLine("Done"); Console.ReadKey(); } static private void print() { try { // Declaring the object variables we will need later object varFileName = "E:\\Test\\test.docx"; object varFalseValue = false; object varTrueValue = true; object varMissing = Type.Missing; // Create a reference to MS Word application Microsoft.Office.Interop.Word._Application varWord = new Microsoft.Office.Interop.Word.Application(); varWord.ActivePrinter = "Microsoft Office Live Meeting 2007 Document Writer"; // Creates a reference to a word document Microsoft.Office.Interop.Word._Document varDoc = varWord.Documents.Open(varFileName, ReadOnly: varFalseValue); // Activate the document varDoc.Activate(); // Print the document object PrintToFile = true; object OutputFileName = "E:\\test\\test.tif"; varDoc.PrintOut(OutputFileName: OutputFileName); varDoc.Close(); varWord.Quit(); varDoc = null; varWord = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } catch (Exception varE) { Console.WriteLine("Error:\n" + varE.Message, "Error message"); } }
Reference From:http://help.lockergnome.com/office/convert-word-doc-file-tif-file--ftopict991689.html
祝,顺利!
Yoyo Jiang[MSFT]
This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
MSDN Community Support | Feedback to us
- 已编辑 Dummy yoyoModerator 2012年3月14日 7:21
- 已标记为答案 sl_water 2012年3月14日 7:27
全部回复
-
Document doc = null;
ApplicationClass app = new ApplicationClass();
app.Visible = false;
app.AlertResponse = (short)1;
string CurrentPath = Server.MapPath("~/test1.vsd");doc = app.Documents.OpenEx(CurrentPath, (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenCopy);//打开一个visio文件
doc.Pages[1].Export(Server.MapPath("~/test1.jpg"));//转换成jpg格式的文件
doc.Close();
app.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(doc);
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);我在网上看到这段代码 我现在试的是word文件但是好像没有 Pages[1].Export 这个方法
-
Hi sl_water,
欢迎来到MSDN论坛。
如果您只是想把office文档转成图片格式,可以使用现成的office工具,Microsoft Office Document Imaging (MODI)。
Office 2003 & 2007:http://office.microsoft.com/en-us/help/about-microsoft-office-document-imaging-HP001077103.aspx
Office 2010:http://support.microsoft.com/kb/982760
如果希望使用代码实现,您可以参考下面的代码:
static void Main(string[] args) { print(); Console.WriteLine("Done"); Console.ReadKey(); } static private void print() { try { // Declaring the object variables we will need later object varFileName = "E:\\Test\\test.docx"; object varFalseValue = false; object varTrueValue = true; object varMissing = Type.Missing; // Create a reference to MS Word application Microsoft.Office.Interop.Word._Application varWord = new Microsoft.Office.Interop.Word.Application(); varWord.ActivePrinter = "Microsoft Office Live Meeting 2007 Document Writer"; // Creates a reference to a word document Microsoft.Office.Interop.Word._Document varDoc = varWord.Documents.Open(varFileName, ReadOnly: varFalseValue); // Activate the document varDoc.Activate(); // Print the document object PrintToFile = true; object OutputFileName = "E:\\test\\test.tif"; varDoc.PrintOut(OutputFileName: OutputFileName); varDoc.Close(); varWord.Quit(); varDoc = null; varWord = null; GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } catch (Exception varE) { Console.WriteLine("Error:\n" + varE.Message, "Error message"); } }
Reference From:http://help.lockergnome.com/office/convert-word-doc-file-tif-file--ftopict991689.html
祝,顺利!
Yoyo Jiang[MSFT]
This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
MSDN Community Support | Feedback to us
- 已编辑 Dummy yoyoModerator 2012年3月14日 7:21
- 已标记为答案 sl_water 2012年3月14日 7:27