時將數據導出通過COM互操作脫穎而出嘗試設置AxisTitle.Text屬性時,我得到一個錯誤(代碼0x800A03EC)。這種情況只有在一個特定的計算機與Windows 7 64位專業版和Excel 2003。我已經試過了多種不同的PC(incuding Win7的X64專業+ Excel 2003中),但不能複製任何其他機器上的錯誤。收到COMException 0x800A03EC設置軸標題
private static void setAxisTitle(_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;
}
}
有人知道如何解決這個困境?
編輯: 在不同文化的話題: 兩個操作系統和Excel具有相同的文化。 不過,我(想我)做處理可能從此出現用下面的代碼的任何問題:如果調用進程中對於辦公設備有不同的文化
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;
}
}
這是一個非常糟糕的Excel錯誤,可能意味着很多事情。你可以谷歌「Excel錯誤1004」,但會有很多cruft挖通過。將機器從第四層窗口放下也可以。祝你好運。 – 2011-01-26 15:32:51
@Hans:ROFL :-) +1用於在兩臺機器上是直截了當的答案 – yas4891 2011-01-26 15:44:09