I m having a code and i want my excel to autofit so i need a help
this is my code
Code
public static void ConvertExcelToPdf(string excelFileIn, string pdfFileOut)Code
{Code
msExcel.Application excel = new msExcel.Application();Code
tryCode
{ excel.Visible = false;Code
excel.ScreenUpdating = false;Code
excel.DisplayAlerts = false;Code
FileInfo excelFile = new FileInfo(excelFileIn);Code
string filename = excelFile.FullName;Code
msExcel.Workbook wbk = excel.Workbooks.Open(filename, missing,Code
missing, missing, missing, missing, missing,Code
missing, missing, missing, missing, missing,Code
missing, missing, missing);Code
wbk.Activate();Code
object outputFileName = pdfFileOut;Code
//wbk.FullName.Replace(".xslx", ".pdf");Code
msExcel.XlFixedFormatType fileFormat = msExcel.XlFixedFormatType.xlTypePDF;Code
// Save document into PDF FormatCode
wbk.ExportAsFixedFormat(fileFormat, outputFileName,Code
Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityMinimum, missing, false,Code
missing, missing,missing,Code
missing);Code
object saveChanges = msExcel.XlSaveAction.xlDoNotSaveChanges;Code
((msExcel._Workbook)wbk).Close(saveChanges, missing, missing);Code
wbk = null;Code
}Code
catch (Exception e)Code
{Code
}Code
finallyCode
{Code
((msExcel._Application)excel).Quit();Code
excel = null;Code
}Code
}
Shankar MRank #874 · 2.5K reputationPosted Jan 13, 2015, 11:37 PM EST
You can set Autofit using the Excel ApplicationClass object created as like ,
Microsoft.Office.Interop.Excel.ApplicationClass XcelApp
= new Microsoft.Office.Interop.Excel.ApplicationClass();
XcelApp.Columns.AutoFit();
Thanks,
Shankar M
Mohammad Hamza KhanRank #5,059 · 313 reputationPosted Jan 14, 2015, 12:11 AM EST
i m getting this problem
Exception from HRESULT: 0x800A03EC