PDA

View Full Version : سوال: تبدیل Exel اکسل و Word ورد به pdf پی دی اف



forodo
سه شنبه 30 مهر 1392, 11:50 صبح
سلام و خسته نباشید
من با open dialog آدرس یک فایل ورد یا اکسل رو می گیرم و بعد چطور می تونم اون رو به صورت پی دی اف داخل بانک اطلاعاتی ذخیره کن؟
با تشکر

CannibalCorpse
چهارشنبه 01 آبان 1392, 11:06 صبح
http://stackoverflow.com/questions/607669/how-do-i-convert-word-files-to-pdf-programmatically

malihehshajari
چهارشنبه 01 آبان 1392, 11:06 صبح
این لینک رو ببین :
http://www.codeproject.com/Questions/346784/How-to-convert-word-document-to-pdf-in-Csharp

CannibalCorpse
چهارشنبه 01 آبان 1392, 11:06 صبح
http://www.dnzone.com/forum/topic/871/

http://www.codeproject.com/Questions/346784/How-to-convert-word-document-to-pdf-in-Csharp

forodo
چهارشنبه 01 آبان 1392, 11:53 صبح
وردش درست شد ممنون
ولی اکسل درست نشد.
اونی که از این سایت گرفتم (http://www.dnzone.com/forum/topic/871/) رو نوشتم ولی ایرادات زیر رو می گیره.
112127

malihehshajari
پنج شنبه 02 آبان 1392, 12:25 عصر
خب خطایی که میده رو بزار ببینیم چیه
حتما باید یک namespace به برنامت اضافه کنی که اون توابع رو بشناسه برنامه

forodo
پنج شنبه 02 آبان 1392, 22:43 عصر
بفرمائید.
این ارورها رو می دهد:
112185

malihehshajari
جمعه 03 آبان 1392, 13:29 عصر
همون که توی پست قبلی گفتم دیگه باید namespace مربوطه رو اضافه کنید لینک زیر رو ببینید
http://www.nullskull.com/q/10339840/save-excel-file-in-format-of-pdf-in-c.aspx

forodo
جمعه 03 آبان 1392, 20:08 عصر
دست همه شما دوستان عزیز درد نکنه. درست شد.
برای تبدیل اکسل به پی دی اف - Conver Exel To PDF

public bool ExportWorkbookToPdf(string workbookPath, string outputPath)
{
// If either required string is null or empty, stop and bail out
if (string.IsNullOrEmpty(workbookPath) || string.IsNullOrEmpty(outputPath))
{
return false;
}

// Create COM Objects
Microsoft.Office.Interop.Excel.Application excelApplication;
Microsoft.Office.Interop.Excel.Workbook excelWorkbook;

// Create new instance of Excel
excelApplication = new Microsoft.Office.Interop.Excel.Application();

// Make the process invisible to the user
excelApplication.ScreenUpdating = false;

// Make the process silent
excelApplication.DisplayAlerts = false;

// Open the workbook that you wish to export to PDF
excelWorkbook = excelApplication.Workbooks.Open(workbookPath);

// If the workbook failed to open, stop, clean up, and bail out
if (excelWorkbook == null)
{
excelApplication.Quit();

excelApplication = null;
excelWorkbook = null;

return false;
}

var exportSuccessful = true;
try
{
// Call Excel's native export function (valid in Office 2007 and Office 2010, AFAIK)
excelWorkbook.ExportAsFixedFormat(Microsoft.Office .Interop.Excel.XlFixedFormatType.xlTypePDF, outputPath);
}
catch (System.Exception ex)
{
// Mark the export as failed for the return value...
exportSuccessful = false;

// Do something with any exceptions here, if you wish...
// MessageBox.Show...
}
finally
{
// Close the workbook, quit the Excel, and clean up regardless of the results...
excelWorkbook.Close();
excelApplication.Quit();

excelApplication = null;
excelWorkbook = null;
}

// You can use the following method to automatically open the PDF after export if you wish
// Make sure that the file actually exists first...
if (System.IO.File.Exists(outputPath))
{
System.Diagnostics.Process.Start(outputPath);
}

return exportSuccessful;
}

برای تبدیل ورد به پی دی اف - Convert Word To PDF

public Microsoft.Office.Interop.Word.Document wordDocument { get; set; }

private void button2_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
wordDocument = appWord.Documents.Open(@"C:\New Microsoft Word Document.docx");
wordDocument.ExportAsFixedFormat(@"C:\New Microsoft Word Document.pdf", WdExportFormat.wdExportFormatPDF);
}