Mohammad Hamza Khan

Mohammad Hamza Khan

  • NA
  • 321
  • 13.7k

Autofit Excel

Jan 13 2015 10:59 PM
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;             
}         
}
 

Answers (2)