Как я могу преобразовать файл Excel в PDF с помощью Winforms С#?C#

Место общения программистов C#
Anonymous
Как я могу преобразовать файл Excel в PDF с помощью Winforms С#?

Сообщение Anonymous »

Microsoft.Office.Interop.Excel.Application execl =
new Microsoft.Office.Interop.Excel.Application();

object oMissing = System.Reflection.Missing.Value;
FileInfo execlFile = new FileInfo(txtNameFile.Text);
execl.Visible = false;
execl.ScreenUpdating = false;
object filename = (object)execlFile.FullName;
Workbook doc = execl.Workbooks.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);
doc.Activate();
object outputFileName = execlFile.FullName.Replace(".Xls", ".pdf");
object fileformat = WdSaveFormat.wdFormatPDF;
doc.SaveAs2(ref outputFileName,
ref fileformat, 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);
object savechanges = WdSaveOptions.wdSaveChanges;
((Workbooks)doc).Close(ref savechanges, ref oMissing, ref oMissing);
doc = null;
((_Application)execl).Quit(ref oMissing, ref oMissing, ref oMissing);
execl = null;
MessageBox.Show("The File has been converted to PDF ");

Вернуться в «C#»