How do I automate the import of data into datasheet using a csv file?
I have a version working that populates data cell by cell in the datasheet.
However I want to import the entire file at once in cases where the data is quite
large ( 7 rows by 1030 columns).
Can I do this in code (c#)?
I think there may be some way of transferring data directly from an array to the
datasheet, but can't find it at the moment.
Failing that, you can parse the CSV data into an array and use something like
this:
Sub ArrayToDataSheet()
Dim oGraph As Graph.Chart
Dim oData As Graph.DataSheet
Dim i As Integer, j As Integer
Dim oSld As PowerPoint.Slide
Dim oShp As Shape
Dim rayData(1 To 6, 1 To 6) As Double
' note that we don't use the first index in the array
' because the first row/column in the graph data sheet
' is the row/column label; don't want to overwrite that
'
' You could get fancier and use an array of strings, include the labels
' and convert the strings to doubles when populating the datasheet from the
array
' blank the array
For i = 2 To UBound(rayData, 1)
For j = 2 To UBound(rayData, 2)
rayData(i, j) = 0
Next j
Next i
' Put some dummy data in the array to test with
rayData(2, 2) = 23.4
rayData(2, 3) = 44.3
rayData(3, 4) = 12.2
rayData(3, 5) = 44.2
Set oSld = ActivePresentation.Slides(1)
Set oShp = oSld.Shapes("TheChart")
oShp.OLEFormat.Activate
Set oGraph = oShp.OLEFormat.Object
Set oData = oGraph.Application.DataSheet
For i = 2 To UBound(rayData, 1)
For j = 2 To UBound(rayData, 2)
oData.Cells(i, j).ClearContents
oData.Cells(i, j) = rayData(i, j)
Next j
Next i
oGraph.Application.Update
End Sub