PDA

View Full Version : سوال: خطای HRESULT در هنگام انتقال اطلاعات دیتا گرید به اکسل



mehdi1367
پنج شنبه 10 اردیبهشت 1394, 00:29 صبح
با سلام
من با استفاده از کتابخانه Microsoft.Office.Interop.Excel در C# می خوام اطلاعات دیتا گرید ویو رو به اکسل انتقال بدم . وقتی تعداد ستون های اطلاعات (فیلدها) کمه مشکلی پیش نمیاد ولی وقتی تعداد ستون ها اضافه می شه با این خطا مواجه می شم :


System.Runtime.InteropServices.COMException was unhandled by user code
HResult=-2146827284
Message=Exception from HRESULT: 0x800A03EC
Source=""
ErrorCode=-2146827284
StackTrace:
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.Range.set_Value(Obj ect RangeValueDataType, Object value)
at ImportValidation.ThisAddIn.removeAnySpaces(Int32 x, Int32 y) in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\Th isAddIn.cs:line 354
at ImportValidation.ThisAddIn.ReadHeaders(Hashtable columnAddress) in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\Th isAddIn.cs:line 123
at ImportValidation.ThisAddIn.mapColumns() in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\Th isAddIn.cs:line 493
at ImportValidation.Ribbon1.button6_Click(Object sender, RibbonControlEventArgs e) in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\Ri bbon1.cs:line 55
at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorag e.ControlActionRaise(IRibbonControl control)
at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorag e.ButtonClickCallback(RibbonComponentImpl component, Object[] args)
at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.In voke(RibbonComponentCallback callback, Object[] args)
at Microsoft.Office.Tools.Ribbon.RibbonMethodInfo.Inv oke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.Sy stem.Reflection.IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
InnerException:


لطفا کمکم کنید . خیلی مهمه برام

مهرداد صفا
پنج شنبه 10 اردیبهشت 1394, 11:41 صبح
سلام.


If you automate Microsoft Excel with Microsoft Visual Basic .NET, Microsoft Visual C# .NET, or Microsoft Visual C++, you may receive the following errors when calling certain methods because the machine has the locale set to something other than US English (locale ID or LCID 1033):
Exception from HRESULT: 0x800A03EC
and/or
Old format or invalid type library
SOLUTION 1:

To get around this error you can set CurrentCulture to en-US when executing code related to Excel and reset back to your originale by using these 2 functions.
//declare a variable to hold the CurrentCulture
System.Globalization.CultureInfo oldCI;
//get the old CurrenCulture and set the new, en-US
void SetNewCurrentCulture()
{
oldCI = System.Threading.Thread.CurrentThread.CurrentCultu re;
System.Threading.Thread.CurrentThread.CurrentCultu re = new System.Globalization.CultureInfo("en-US");
}
//reset Current Culture back to the originale
void ResetCurrentCulture()
{
System.Threading.Thread.CurrentThread.CurrentCultu re = oldCI;
}
SOLUTION 2:

Another solution that could work, create a 1033 directory under Microsoft Office\Office11 (or your corresponding office-version), copy excel.exe to the 1033 directory, and rename it to xllex.dll.
Although you might solve the problem using one off these solutions, when you call the Excel object model in locales other than US English, the Excel object model can act differently and your code can fail in ways you may not have thought of. For example, you might have code that sets the value of a range to a date:
yourRange.Value2 = "10/10/09"
Depending on the locale this code can act differently resulting in Excel putting into the range any of the following values:
October 10, 2009 September 10, 2009 October 9, 201


http://www.made4dotnet.com/Default.aspx?tabid=141&aid=15

leila1200
یک شنبه 12 آذر 1396, 15:31 عصر
با سلام و خسته نباشید من موقع انتقال اطلاعات از data grid به اکسل 147197 این خطا می ده لطفا کمکم کنید ممنون میشم