开发者

COMException 0x800A03EC when setting axis title

When exporting data to excel via COM Interop I get an error (code 0x800A03EC) when trying to set the AxisTitle.Text property. This happens ONLY on one specific computer with Windows 7 x64 Professional and Excel 2003. I've tried it on a variety of different PCs (incuding Win7 x64 Professional + Excel 2003) but can't reproduce that error on any other machine.

private static void setAxisTitl开发者_开发问答e(_Chart tChart, string aszTimeUnit)
    {
        Axis tAxis = (Axis)tChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary);
        try
        {
            tAxis.HasTitle = true;
            tAxis.AxisTitle.Text = "Messwert [um/m]";
            tAxis = (Axis)tChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);
            tAxis.HasTitle = true;
            tAxis.AxisTitle.Text = string.Format("Zeit [{0}]", aszTimeUnit);
        }
        catch (Exception aEx)
        {
            cLogger.ErrorFormat("error setting axis title for time unit '{0}' on Axis '{1}'", aszTimeUnit, tAxis.AxisTitle);
            cLogger.Error("error stack trace:", aEx);
            throw;
        }
    }

Someone got any idea how to solve this dilemma?

EDIT: On the topic of differing cultures: Both OS and Excel have the same culture. HOWEVER, I (think I) do handle any problems that may arise from this with the following code:

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

        try
        {
            Thread.CurrentThread.CurrentCulture = cExcelCulture;
            int tVersion;
            bool tParseSucceded = Int32.TryParse(tExcel.Version.Substring(0, tExcel.Version.IndexOf('.')), out tVersion);

            // 12 is the first version with .xlsx extension
            if (tVersion >= 12)
                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;
        }
    }


This error sometimes happen when the calling process has a different culture in respect to the office installation. If this is your case you can change the calling thread culture to match the Excel culture like this:

CultureInfo MyCulture = new CultureInfo("en-US"); // your culture here Thread.CurrentThread.CurrentCulture = MyCulture;

This could possibly fix the problem.


For Each Obj As Excel.ChartObject In xlsSheet.ChartObjects()
    ' Obj.Copy()
    If Obj.Name.ToString = "Chart gainloose" Then
        Obj.Chart.ChartArea.Copy()

    End If
    ' Console.WriteLine(Obj.Name)
    ' Console.WriteLine(Obj.TopLeftCell.Row.ToString & " : " & Obj.TopLeftCell.Column.ToString)
Next
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜