Click here to Skip to main content
15,892,480 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: [VS10] Debug and Release build problem Pin
The Mighty Atom13-Jul-11 5:51
The Mighty Atom13-Jul-11 5:51 
QuestionUse event on Runtime Pin
ivo753-Jul-11 11:04
ivo753-Jul-11 11:04 
AnswerRe: Use event on Runtime Pin
JR2123-Jul-11 19:10
JR2123-Jul-11 19:10 
AnswerRe: Use event on Runtime Pin
Johan Hakkesteegt5-Jul-11 2:03
Johan Hakkesteegt5-Jul-11 2:03 
AnswerRe: Use event on Runtime Pin
Simon_Whale5-Jul-11 2:12
Simon_Whale5-Jul-11 2:12 
QuestionProblem using Package and Deployment Wizard Pin
Shouvik262-Jul-11 0:53
Shouvik262-Jul-11 0:53 
AnswerRe: Problem using Package and Deployment Wizard Pin
Dr.Walt Fair, PE2-Jul-11 18:58
professionalDr.Walt Fair, PE2-Jul-11 18:58 
QuestionExcel interop & filling columns from an array (VB.NET 3.5) Pin
Steven St. John1-Jul-11 6:50
Steven St. John1-Jul-11 6:50 
I've been banging my head against the wall on this one for several hours and would appreciate some help!

Big picture: I am writing a program that reads certain disk files, processes the data in various ways, graphically displays the data, etc. The user will be able to select a subset of the processed data to save to an Excel file.

I am crafting a class I call LAExcelWrapper to perform this work. The project references Microsoft Excel 14.0 Object Library (released, I take it, with Microsoft Excel 2010).

Several of the Excel Worksheets should hold data that are essentially in the form of frequency tables. One of these, an "ILI histogram" (never mind what that is in the real world) is held in my program as a Dictionary(Of Integer, Integer). The Key is an integer that represents a number of milliseconds and the Value is an integer representing a Count falling within that time range.

The Dictionary is a property (named ILIHistogram) of a custom class nested within other classes. However, all of the ILIHistograms share the same Keys. So my excel spreadsheet needs to have the first column be the Keys from the first instance, and then iterate through all of the instances placing the Values in the Excel columns.

Consider the following code:

Private Sub ILIHistogramSheet()
    'xlSheet is declared at class level; ReturnReferenceToNextSheet is a helper function
    'The lines work, delivering the ActiveSheet to xlSheet.
    xlSheet = ReturnReferenceToNextSheet()
    xlSheet.Name = "ILI histograms"

    'Converting the Keys of the first instance to an array of integers
    Dim a() As Integer = mData(0).Trials(0).ILIHistogram.Keys.ToArray
    Dim r As Excel.Range
    Dim rows As Integer = a.GetUpperBound(0) + 1

    'Here, I want to fill the data in the first column, starting at row 7
    r = DirectCast(xlSheet.Cells(6, 1), Excel.Range).Resize(6 + rows, 1)
    r.Value = a
End Sub


What I was hoping would happen would be that column 1 (starting at row 7) would now fill with the integer values of my Keys. Instead, it fills with only the first Key. For example, if my keys are 10, 20, 30, 40, 50, this code gives me (starting at row 7):

10
10
10
10
10

If I alter the code above so that the range is resized as follows:
'Set range to be one row rather than one column
r = DirectCast(xlSheet.Cells(6, 1), Excel.Range).Resize(1, 6 + rows)


I get what you'd kind of expect:

10 20 30 40 50

So, frustratingly, Excel seems to use the index of the array as the column number of the range, when I want it to use it as the row number.

I can certainly get this code to work by looping through my arrays and creating one-cell ranges on the fly, but I imagine this would be terribly slow.

I can probably fool around with accessing Excel's Paste Special through interop and fill the spreadsheet "wrong" first, cut all of the data and transpose paste it, but this seems less than elegant (and given how hard Excel interop seems to be, I'm not sure I'll be able to pull it off).

Any thoughts?
AnswerRe: Excel interop & filling columns from an array (VB.NET 3.5) Pin
Alan N1-Jul-11 10:56
Alan N1-Jul-11 10:56 
GeneralRe: Excel interop & filling columns from an array (VB.NET 3.5) [modified] Pin
Steven St. John1-Jul-11 13:15
Steven St. John1-Jul-11 13:15 
QuestionWebService monOccurs and maxOccurs Without Nillable [modified] Pin
KenBonny29-Jun-11 22:44
KenBonny29-Jun-11 22:44 
QuestionVBA text problem Pin
KORCARI28-Jun-11 10:51
KORCARI28-Jun-11 10:51 
AnswerRe: VBA text problem Pin
ChandraRam29-Jun-11 3:44
ChandraRam29-Jun-11 3:44 
AnswerRe: VBA text problem Pin
Dalek Dave29-Jun-11 5:44
professionalDalek Dave29-Jun-11 5:44 
QuestionInstaller [modified] Pin
KenBonny27-Jun-11 4:17
KenBonny27-Jun-11 4:17 
AnswerRe: Installer Pin
KenBonny27-Jun-11 21:22
KenBonny27-Jun-11 21:22 
QuestionDeviceID from CD Pin
JR21225-Jun-11 20:15
JR21225-Jun-11 20:15 
AnswerRe: DeviceID from CD Pin
JR21225-Jun-11 23:43
JR21225-Jun-11 23:43 
QuestionUsing LINQ to Objects to generate a frequency table - returned as a Dictionary [modified] Pin
Steven St. John25-Jun-11 5:28
Steven St. John25-Jun-11 5:28 
QuestionAdd Reference At Runtime Pin
Milad.Biroonvand23-Jun-11 8:47
Milad.Biroonvand23-Jun-11 8:47 
AnswerRe: Add Reference At Runtime Pin
Eddy Vluggen23-Jun-11 9:12
professionalEddy Vluggen23-Jun-11 9:12 
QuestionVB and MS Excel Pin
geekgautam23-Jun-11 3:07
geekgautam23-Jun-11 3:07 
AnswerRe: VB and MS Excel Pin
David Mujica23-Jun-11 3:28
David Mujica23-Jun-11 3:28 
GeneralRe: VB and MS Excel Pin
geekgautam23-Jun-11 18:26
geekgautam23-Jun-11 18:26 
GeneralRefresh Data Pin
David Mujica24-Jun-11 6:25
David Mujica24-Jun-11 6:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.