I use Access 2007, SQL Server 2005 and 2008, and C#.net with VS20010.
I need to validate, then import an Excel workbook that has been posted to a SP document library. I wrote the program using VBA in A2k7 so I could get it working, get all my thoughts together, etc. Shortly, I’m going to start converting it to C# so I can run it on a scheduled basis from my SQL Server agent. Authentication may be fun, we’ll see.
In my Access VBA program, I use a simple statement to create a multi-dimensional array of “variants”. This allows me to test every single cell for the correct type before I try to assign it to a local variable. Certain cells must be numeric. Others, I use as strings, even if they’re numeric. Since the data may be hand-entered, I could see virtually any content in the cells…one of the reasons I don’t just import it, since most import vehicles (ACCESS, SSIS) use Excel’s determination as to the column’s “type”.
'
' Get the range of used cells from the worksheet and stuff it into an array
'
xlApp.visible = False 'Don't let the workbook be shown
Set xlWB = xlApp.Workbooks.Open(URL) 'Open the workbook
Set xlSH = xlWB.Worksheets(1) 'Must be the first worksheet in the workbook
HandleMessages 1, 0, 1, "Working on Workbook " & xlWB.NAME & ", Worksheet " & xlSH.NAME
Set xlRA = xlSH.UsedRange 'xlRA is the range of cells in the first workbook that are "USED"
strSheetArray = xlRA 'This sets an array of variants to the two dimensional range xlRA
So, going to C#, what do I do about the lack of a non-typed “variant”? How do I proceed? Anyone done it?
You can use
dynamicin C# 4.0.http://msdn.microsoft.com/en-us/library/dd264736.aspx
The link shows examples of using
dynamicwith Excel.