Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I achieve that in .NET/C#?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
433 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could use this code snippet: (taken from one of my projects, so not guaranteed to work out of the box)

Microsoft.Office.Interop.Excel.Application tExcel = new Application();
CultureInfo cSystemCulture = Thread.CurrentThread.CurrentCulture;
CultureInfo cExcelCulture = new CultureInfo(tExcel.LanguageSettings.get_LanguageID(
    Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI));

try
{
    Thread.CurrentThread.CurrentCulture = cExcelCulture;
    double tVersion;
    bool tParseSucceded = double.TryParse(tExcel.Version, out tVersion);

    // 12 is the first version with .xlsx extension
    if (tVersion > 11.5)
        cDefaultExtension = ".xlsx";
    else
        cDefaultExtension = ".xls";

}
catch (Exception aException)
{
    cLogger.Debug("error retrieving excel version.", aException);
    cLogger.Error("error retrieving excel version.");
}
finally
{
    Thread.CurrentThread.CurrentCulture = cSystemCulture;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...