I m having a code and i want my excel to autofit so i need a help
this is my code
public static void ConvertExcelToPdf(string excelFileIn, string pdfFileOut)
{ msExcel.Application excel = new msExcel.Application();
try { excel.Visible = false; excel.ScreenUpdating = false; excel.DisplayAlerts = false; FileInfo excelFile = new FileInfo(excelFileIn);
string filename = excelFile.FullName; msExcel.Workbook wbk = excel.Workbooks.Open(filename, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing,
missing, missing, missing);
wbk.Activate();
object outputFileName = pdfFileOut; //wbk.FullName.Replace(".xslx", ".pdf"); msExcel.XlFixedFormatType fileFormat = msExcel.XlFixedFormatType.xlTypePDF;
// Save document into PDF Format wbk.ExportAsFixedFormat(fileFormat, outputFileName,
Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityMinimum, missing, false,
missing, missing,missing,
missing);
object saveChanges = msExcel.XlSaveAction.xlDoNotSaveChanges;
((msExcel._Workbook)wbk).Close(saveChanges, missing, missing); wbk = null; }
catch (Exception e)
{ }
finally { ((msExcel._Application)excel).Quit(); excel = null; }
}
Mohammad Hamza KhanPosted Jan 14, 2015, 5:11 AM
i m getting this problem
Exception from HRESULT: 0x800A03EC
Shankar MPosted Jan 14, 2015, 4:37 AM
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