PS: There is a super big job in the company's business to convert OFFICE documents into PDF. I guess there were no programmers before, and those people in the company should have manually transferred them one by one. I strongly sigh for the apes that I have done so many things for you, and I am still complaining... I cannot meet your needs;
The Microsoft Net platform provides very good support for Office documents; among them, there are com components directly integrated into VS. Using these APIs can quickly eliminate many tedious tasks;
The following codes are written out after reading the company's code; the code is presented:
using System; using ; using ; using ; using ; using ; using ; //Office namespacenamespace OfficeToPdf { //Excel class class ExcelConverter { //Constructor public ExcelConverter() { } /// <summary> /// Convert excel to PDF document /// </summary> /// <param name="_lstrInputFile">origin file path</param> /// <param name="_lstrOutFile">pdf file output path</param> /// <returns>true Success</returns> public bool ConverterToPdf(string _lstrInputFile,string _lstrOutFile) { lobjExcelApp = null; lobjExcelWorkBooks = null; lobjExcelWorkBook = null; string lstrTemp = ; object lobjMissing = ; try { lobjExcelApp = new (); = true; lobjExcelWorkBooks = ; lobjExcelWorkBook = (_lstrInputFile, true, true, lobjMissing, lobjMissing, lobjMissing, true, lobjMissing, lobjMissing, lobjMissing, lobjMissing, lobjMissing, false, lobjMissing, lobjMissing); // This function will not be available after 12.0.0.0 lstrTemp = () + ().ToString() + ".xls" + ( ? 'm' : 'x'); //lstrTemp = () + ().ToString() + ".xls"; (lstrTemp, .xlExcel4Workbook, , , , false, , , false, , , ); //The output is PDF. The first option specifies that it is transferred to PDF, and can also be specified as XPS format. (, _lstrOutFile, , , false, , , false, ); (); (); } catch (Exception ex) { //Other log operations; return false; } finally { if (lobjExcelWorkBook != null) { (,,); (lobjExcelWorkBook); lobjExcelWorkBook = null; } if(lobjExcelWorkBooks != null) { (); (lobjExcelWorkBooks); lobjExcelWorkBooks = null; } if(lobjExcelApp != null) { (); (lobjExcelApp); lobjExcelApp = null; } //Actively activate the garbage collector, mainly to avoid excessive memory usage when converting documents in large quantities, and the garbage collector is not running all the time! (); (); } return true; } } }
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for your study or work. Thank you for your support. If you want to know more about it, please see the following links