questions

Sep 11, 2012 at 9:04 AM

Hi Sebastian,
i have some questions for you :)


Q1: about saving

Actually, i save my workbook like that :

String workbookFile = String.Format(@"d:\myExcelFile{0}", GetDefaultExtension( _exApplication ));
workBook.SaveAs(workbookFile);

String GetDefaultExtension(Excel.Application application)
{
    double version = Convert.ToDouble(application.Version, CultureInfo.InvariantCulture);
    if ( version >= 12.00 )
        return ( ".xlsx" );
    return ( ".xls" );
}

So it's ok.

With Excel 2007, it is possible to save a file that is compatible with Excel 2003.
How can i do that from my c# code ?

Just forcing the .xls extension is not enough i think !


Q2: about saving file which contains VBA code

I have generated from my c# code Excel files with VBA code (this works very well for both 2003 & 2007 versions)

I save my workbook like that :

String workbookFile = String.Format(@"d:\myExcelFile{0}", GetDefaultExtension( _exApplication ));
workBook.SaveAs(workbookFile, GetFileFormat(_exApplication));

String GetDefaultExtension(Excel.Application application)
{
    double version = Convert.ToDouble(application.Version, CultureInfo.InvariantCulture);
    if ( version >= 12.00 )
        return ( ".xlsm" );
    return ( ".xls" );
}

XlFileFormat GetFileFormat(Excel.Application application)
{
    double version = Convert.ToDouble(application.Version, CultureInfo.InvariantCulture);
    if ( version >= 12.00 )
        return ( XlFileFormat.xlOpenXMLWorkbookMacroEnabled );
    return ( XlFileFormat.xlExcel7 );
}

My question 2 is not far away from Q1. Is it possible to save an Excel 2007 file (with macros) that is compatible with Excel 2003

So the file result extension will be .xls

What XlFileFormat should i use to achived this ?


thank you very much
Fred


------

I use NetOffice 1.5.1 (sept 01 2012)

Coordinator
Sep 12, 2012 at 5:51 AM

XlFileFormat.xlExcel8 is the best way for Q1 and Q2 :-)

if you want alway a .xls file then try the follows

XlFileFormat GetFileFormat(Excel.Application application)
{
    double version = Convert.ToDouble(application.Version, CultureInfo.InvariantCulture);
    if ( version >= 12.00 )
        return ( XlFileFormat.xlExcel8);
   else
       return (XlFileFormat.xlWorkbookNormal);
}

Sep 12, 2012 at 9:05 PM

this works perfectly

thx again !

Fred