Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Formatting lost when saving excel 2003 file using excel 2007 | Excel Discussion (Misc queries) | |||
"Excel encountered an error and had to remove some formatting toavoid corrupting the workbook. Please re-check your formatting carefully." | Excel Discussion (Misc queries) | |||
Saving Excel 2007 conditional formatting in Excel 2003 format | Excel Discussion (Misc queries) | |||
Find formatting in text in cell, insert tags around formatting. | Excel Programming | |||
error: Excel encountered an error and had to remove some formatting to avoid corrupting the workbook; please recheck your formatting carefully | Excel Programming |