Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Writing data to an excel workbook

I'm pulling data from a Sql 2k5 table, looping through cols & rows and
populating the sheet.cells object, eventually I'm getting a famous Excel
error: Excel Exception HRESULT: 0x800A03EC. The code I'm getting the error
in is pasted into this post, I've read, and experienced, that this is VERY
slow. I read an article that some guy put the data into an ArrayList then
populated the cells that way but didn't show any code so it didn't help much.
I'd appreciate any help since I think I'll probably be fired soon if I don't
get this done ASAP; not to put that on anyone elses shoulders just some
advice would be great. At this point it's almost faster to do this by hand,
I'd really like to speed this up.

Code throwing the error:

foreach (Object obj in ColData)
{
string rowData = obj.ToString();
oSheet.Cells[iRow, colNum] = rowData;
colNum++;
}
iRow++;

Explaination: ColData at this point is an ArrayList, I'm putting the data
into a string thinking that maybe just passing in a string directly would be
better, NOPE. iRow is a variable that is dynamic, it won't be the same all
the time. It will never be less than zero and colNum is equal to the number
assigned to column the ColumnName is in. This is a complicated application
since it is a backend app to a WebApp, it appears that the data is being
written to the proper cells but this error is killing me, it is also
EXTREMELY SLOW.

Thanks all.

--
Kevin C. Brown
Developer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Writing data to an excel workbook

In VBA, you can dump the whole array in one go. Can't say about you chosen
language.
Certainly faster than writing a cell at a time.

Private Sub CommandButton1_Click()
Dim TempStr() As String

TextBox1.Text = "Line 1" & vbNewLine & "Line 2" & vbNewLine & "Line 3" &
vbNewLine & "Line 4" & vbNewLine & "Line 5"

TempStr = Split(TextBox1.Text, vbNewLine)

Range("A1").Resize(15).Value = Application.Transpose(TempStr)
'Or
Range("A1").Resize(UBound(TempStr) + 1).Value =
Application.Transpose(TempStr)

End Sub

NickhK

"KevinB" wrote in message
...
I'm pulling data from a Sql 2k5 table, looping through cols & rows and
populating the sheet.cells object, eventually I'm getting a famous Excel
error: Excel Exception HRESULT: 0x800A03EC. The code I'm getting the

error
in is pasted into this post, I've read, and experienced, that this is VERY
slow. I read an article that some guy put the data into an ArrayList then
populated the cells that way but didn't show any code so it didn't help

much.
I'd appreciate any help since I think I'll probably be fired soon if I

don't
get this done ASAP; not to put that on anyone elses shoulders just some
advice would be great. At this point it's almost faster to do this by

hand,
I'd really like to speed this up.

Code throwing the error:

foreach (Object obj in ColData)
{
string rowData = obj.ToString();
oSheet.Cells[iRow, colNum] = rowData;
colNum++;
}
iRow++;

Explaination: ColData at this point is an ArrayList, I'm putting the data
into a string thinking that maybe just passing in a string directly would

be
better, NOPE. iRow is a variable that is dynamic, it won't be the same

all
the time. It will never be less than zero and colNum is equal to the

number
assigned to column the ColumnName is in. This is a complicated

application
since it is a backend app to a WebApp, it appears that the data is being
written to the proper cells but this error is killing me, it is also
EXTREMELY SLOW.

Thanks all.

--
Kevin C. Brown
Developer



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Writing data to an excel workbook

Sweet example NickHK.

Is there a delimiter you can use for cells as well?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing a formula in Excel spreadsheet to track how long data has flyboy719 Excel Worksheet Functions 2 January 20th 10 09:59 AM
Writing to another workbook Eric Hearn Excel Worksheet Functions 0 March 7th 08 02:15 PM
When writing a macro in excel workbook, how do I refer to ea cell Diana Bartz Excel Programming 1 July 7th 05 09:51 PM
Reading Writing Data from One WorkBook to Another John Pierce Excel Programming 0 May 30th 05 09:23 PM
Reading data from an excel sheet and writing to another Rain Excel Programming 1 January 19th 05 09:25 AM


All times are GMT +1. The time now is 11:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"