OWC Spreadsheet Cell values in C#

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()
 
S

someone

OK - resolved this last night.

I don't know what changed - but the methods and properties for .Text,
..MergeCells etc. are now showing up in VS 2005 - so I can successfully get
individual cell values.

I might still need to copy all the spreadsheet values into an array for
processing speed - which is what I assume .get_values is for.
So I will still try and get that working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top