以下为 Excel 2007 编写的代码将范围格式化为表格,没有问题。
SourceRange.Worksheet.ListObjects.Add(XlListObjectSourceType.xlSrcRange,
SourceRange, System.Type.Missing, XlYesNoGuess.xlYes, System.Type.Missing).Name = TableName;
SourceRange.Worksheet.ListObjects[TableName].TableStyle = TableStyleName;
SourceRange.AutoFilter(1, Type.Missing, XlAutoFilterOperator.xlAnd, Type.Missing, true);
if (IsGroupTable)
{
SourceRange.Rows.Group(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
当我尝试在 Excel 2003 中使用相同的代码时,我收到以下错误:
Type : System.Runtime.InteropServices.COMException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
Source : mscorlib
Help link :
ErrorCode : -2147352573
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Object ForwardCallToInvokeMember(System.String, System.Reflection.BindingFlags, System.Object, Int32[], System.Runtime.Remoting.Proxies.MessageData ByRef)
Stack Trace : at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.ListObjects.Add(XlListObjectSourceType SourceType, Object Source, Object LinkSource, XlYesNoGuess XlListObjectHasHeaders, Object Destination)
我不确定是什么导致此错误发生,是否可以挽救?