Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write to Excel form

Status
Not open for further replies.

caslan

MIS
May 18, 2001
3
US
I wanting to extract data from a external database to an excel spreadsheet. I am having trouble writing each field of my recordset to an individual cell in the spreadsheet. Does anyone have an idea as to how I could perform this task. Thank you in advance.
 
Here is a piece of code, I used to populate Excel sheets.

sub create_excel_sheet()
set xlApp= createobject("excel.application")
xlApp.SheetsInNewWorkbook = 1
Set wkbNew = xlApp.Workbooks.Add
'strBookName = "c:\R2D2_book.xls"
strBookName = Xl_fname

wscript.stdout.writeline
wscript.stdout.writeline "Xl_fname = "&Xl_fname
wscript.stdout.writeline

wkbNew.SaveAs strBookName
set worksheet=wkbNew.worksheets("Sheet1")
end sub

'************ open inXl file, write to excel sheet ***

sub write_to_Xl_sheet()
'Xl_in_file
wscript.stdout.writeline " XlinFile is " &Xl_in_file
Set fsXl = CreateObject("Scripting.FileSystemObject")
Set fsXl = fsXl.OpenTextFile(Xl_in_file, ForReading)

'Set up the Headings on the 1st row the spreadsheet

worksheet.cells(1,1) = "Port_no"
worksheet.cells(1,2) = "Align_err"
worksheet.cells(1,3) = "Fcs_err"
worksheet.cells(1,4) = "Xmit_err"
worksheet.cells(1,5) = "Rcv_err"
worksheet.cells(1,6) = "Under_size"
fsxl.skipline
i=2
do while fsXl.AtEndOfStream = false

in_buf = fsXl.ReadLine
'wscript.stdout.writeline "in_buf is "&in_buf



'wscript.stdout.writeline worksheet.Cells(i,1)
port_no =left(in_buf, 5)
Align_err =mid(in_buf, 7,10)
fcs_err =mid(in_buf, 18,10)
xmit_err =mid(in_buf,29,10)
rcv_err =mid(in_buf,40,10)
under_size =mid(in_buf,51,10)


worksheet.cells(i,1) = port_no
worksheet.cells(i,2) = Align_err
worksheet.cells(i,3) = fcs_err
worksheet.cells(i,4) = xmit_err
worksheet.cells(i,5) = rcv_err
worksheet.cells(i,6) = under_size

'wscript.stdout.writeline "col1 is "&port_no
'wscript.stdout.writeline "col2 is "&Align_err

inbuf=""

i=i+1

loop

xlApp.application.quit
fsXl.close
end sub

ammu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top