S
someone
This is probably a really dumb question - but I have wasted several hours
today trying to find an answer without success.
I;ve tried Alvin's book, Google searches, Microsoft help, OWCDSS11.chm
etc..
How do you get / set the values of cells in an OWC spreadsheet using C#?
I have tried various combinations of values for the RangeValueDataType,
and various types for the returned object (including (object[,]) using
get_Value but can't get anything that runs without giving me a COM
Exception.
If someone could give me a complete example of reading and writing a cell
value using C# I would be really greatful.
Thanks
Some pieces of failing code:
object[,] valuearray = my_range.get_Value(0x10);
if (valuearray[1,1] == "") {
// empty cell
}
....
my_range.get_Item(1,1).set_Value("Total");
An example of the latest COM Exception:
System.Runtime.InteropServices.COMException was unhandled
Message="Type mismatch. (Exception from HRESULT: 0x80020005
(DISP_E_TYPEMISMATCH))"
Source="Microsoft.Office.Interop.Owc11"
ErrorCode=-2147352571
StackTrace:
at Microsoft.Office.Interop.Owc11.RangeClass.get_Value(Object
RangeValueDataType)
at XLS2XML.XLS2XMLTAB.xlws_parse(Range owc_rng) in C:\WinXP\Visual
Studio Projects\DLXML\XLS2XML\XLS2XML\XLS2XMLTAB.cs:line 63
at XLS2XML.Form1.btn_parse_Click(Object sender, EventArgs e) in C:
\WinXP\Visual Studio Projects\DLXML\XLS2XML\XLS2XML\Form1.cs:line 153
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage
(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsa
feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,
Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop
(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at XLS2XML.Program.Main() in C:\WinXP\Visual Studio Projects\DLXML
\XLS2XML\XLS2XML\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
today trying to find an answer without success.
I;ve tried Alvin's book, Google searches, Microsoft help, OWCDSS11.chm
etc..
How do you get / set the values of cells in an OWC spreadsheet using C#?
I have tried various combinations of values for the RangeValueDataType,
and various types for the returned object (including (object[,]) using
get_Value but can't get anything that runs without giving me a COM
Exception.
If someone could give me a complete example of reading and writing a cell
value using C# I would be really greatful.
Thanks
Some pieces of failing code:
object[,] valuearray = my_range.get_Value(0x10);
if (valuearray[1,1] == "") {
// empty cell
}
....
my_range.get_Item(1,1).set_Value("Total");
An example of the latest COM Exception:
System.Runtime.InteropServices.COMException was unhandled
Message="Type mismatch. (Exception from HRESULT: 0x80020005
(DISP_E_TYPEMISMATCH))"
Source="Microsoft.Office.Interop.Owc11"
ErrorCode=-2147352571
StackTrace:
at Microsoft.Office.Interop.Owc11.RangeClass.get_Value(Object
RangeValueDataType)
at XLS2XML.XLS2XMLTAB.xlws_parse(Range owc_rng) in C:\WinXP\Visual
Studio Projects\DLXML\XLS2XML\XLS2XML\XLS2XMLTAB.cs:line 63
at XLS2XML.Form1.btn_parse_Click(Object sender, EventArgs e) in C:
\WinXP\Visual Studio Projects\DLXML\XLS2XML\XLS2XML\Form1.cs:line 153
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage
(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.Unsa
feNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,
Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop
(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at XLS2XML.Program.Main() in C:\WinXP\Visual Studio Projects\DLXML
\XLS2XML\XLS2XML\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()