Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default excel formatting for .net

I would like to know how to change the late binding .net detail coding lines
to early binding .net coding. I would like to know so that I can use the
'VBA' similar code that .net has. This way I will be able to use the
formatting options that excel has. I plan to run an excel scritping macro and
use the code in macro.

Thus how can I change the late binding .net coding for (for the variable
amount of detail lines that can occur on each coding line.

The line I am referring to is:
For i = 0 to ds.Tables (0).Rows.Count - 1
For j = 0 to ds.Tables (0).Columns.Count - 1
xlWorkSheet.Cells (i + 1, j + 1) = _
ds.Tables (0).Rows (i).Item (j)
Next

The code above is part of the code listed below:

Private Sub ShowReport_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles Button1.Click
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim xlClApp As Excel.ApplicationClass
Dim excelFile As String = " "
Dim dt As DataTable
Dim da4 As SqlDataAdapter
cnn4 = New SqlConnection(connectionString)
cmd4 = New SqlCommand("stored procedure name", cnn4)
cmd4.CommandType = CommandType.StoredProcedure
With cmd4
..Parameters.Add("@parm1", SqlDbType.VarChar).Value = strParm1
..Parameters.Add("@parm2", SqlDbType.VarChar).Value = strParm2
End With
da4 = New SqlDataAdapter(cmd4)
da4.Fill(ds4)
xlApp = New Excel.Application
xlClApp = New Excel.ApplicationClass
xlApp.Workbooks.Add()
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = CType(xlWorkBook.Sheets("sheet1"),
Microsoft.Office.Interop.Excel.Worksheet)
xlApp.Visible = False
xlApp.ScreenUpdating = True
dt = ds4.Tables(0)
'Add the column headings for the from the dataset
Dim dc As DataColumn
Dim iCols As Int32 = 0
For Each dc In dt.Columns
xlWorkSheet.Range("A1").Offset(0, iCols).Value = dc.ColumnName
xlWorkSheet.Range("A1").Offset(0, iCols).Font.Bold = True
xlWorkSheet.Range("A1").Offset(0, iCols).BorderAround()
iCols += 1
Next

For i = 0 to ds.Tables (0).Rows.Count - 1
For j = 0 to ds.Tables (0).Columns.Count - 1
xlWorkSheet.Cells (i + 1, j + 1) = _
ds.Tables (0).Rows (i).Item (j)
Next

excelFile = "c:\exceltst.xls"
xlWorkBook.Sheets("sheet1").SaveAs(excelFile)
xlWorkBook.Close()
xlApp.Quit()
xlWorkSheet = Nothing
xlWorkBook = Nothing
xlClApp = Nothing
da4.Dispose()
cmd4.Dispose()
cnn4.Close()

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
Formatting lost when saving excel 2003 file using excel 2007 Anamika Excel Discussion (Misc queries) 1 December 29th 08 04:24 PM
"Excel encountered an error and had to remove some formatting toavoid corrupting the workbook. Please re-check your formatting carefully." Greg Lovern Excel Discussion (Misc queries) 0 July 18th 08 09:42 PM
Saving Excel 2007 conditional formatting in Excel 2003 format [email protected] Excel Discussion (Misc queries) 0 March 28th 08 06:42 AM
Find formatting in text in cell, insert tags around formatting. CarlC Excel Programming 2 February 27th 08 09:26 PM
error: Excel encountered an error and had to remove some formatting to avoid corrupting the workbook; please recheck your formatting carefully Keith Excel Programming 0 January 31st 07 05:38 PM


All times are GMT +1. The time now is 02:21 PM.

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

About Us

"It's about Microsoft Excel"