Click here to Skip to main content
15,918,808 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: ListBox Control Pin
nlarson1116-Nov-06 6:15
nlarson1116-Nov-06 6:15 
AnswerRe: ListBox Control Pin
Dave Kreskowiak16-Nov-06 6:20
mveDave Kreskowiak16-Nov-06 6:20 
GeneralRe: ListBox Control Pin
CodingYoshi16-Nov-06 6:36
CodingYoshi16-Nov-06 6:36 
GeneralRe: ListBox Control Pin
CodingYoshi16-Nov-06 6:43
CodingYoshi16-Nov-06 6:43 
Questiondata from VB.NET to MS Excel Pin
Johan Hakkesteegt16-Nov-06 4:04
Johan Hakkesteegt16-Nov-06 4:04 
AnswerRe: data from VB.NET to MS Excel Pin
Kevin Nicol16-Nov-06 4:19
Kevin Nicol16-Nov-06 4:19 
GeneralRe: data from VB.NET to MS Excel Pin
Johan Hakkesteegt16-Nov-06 4:55
Johan Hakkesteegt16-Nov-06 4:55 
AnswerRe: data from VB.NET to MS Excel Pin
Kevin Nicol16-Nov-06 7:16
Kevin Nicol16-Nov-06 7:16 
Here is a simple app that takes a dataset and writes a worksheet per data table in the set

Public Sub writeToExcel(ByVal source As DataSet)
Dim doc As New System.IO.StreamWriter("Excel.xls") 'use .xls even though its an xml file

Dim startExcelXML As String = ""

startExcelXML &= "<xml version>"
startExcelXML &= vbNewLine & "<Workbook " + "xmlns=""urn:schemas-microsoft-com:office:spreadsheet"""
startExcelXML &= vbNewLine & Microsoft.VisualBasic.Chr(10) & "" + " xmlnsBlush | :O =""urn:schemas-microsoft-com:office:office"""
startExcelXML &= vbNewLine & "xmlns:x=""urn:schemas- microsoft-com:office:" + "excel"""
startExcelXML &= vbNewLine & "xmlns:ss=""urn:schemas-microsoft-com:" + "office:spreadsheet"">"


'write the styles tags that format the data and cells properly
startExcelXML &= vbNewLine & "<Styles>"

startExcelXML &= vbNewLine & " <Style ss:ID=""Default"" ss:Name=""Normal"">"
startExcelXML &= vbNewLine & " <Alignment ss:Vertical=""Bottom""/>"
startExcelXML &= vbNewLine & " <Borders/>"
startExcelXML &= vbNewLine & " <Font/>"
startExcelXML &= vbNewLine & " <Interior/>"
startExcelXML &= vbNewLine & " <NumberFormat/>"
startExcelXML &= vbNewLine & " <Protection/>"
startExcelXML &= vbNewLine & " </Style>"

startExcelXML &= vbNewLine & "<Style ss:ID=""ColHeader"">"
startExcelXML &= vbNewLine & "<Alignment ss:Horizontal=""Center"" ss:Vertical=""Bottom""/>"
startExcelXML &= vbNewLine & "<Font x:Family=""Swiss"" ss:Size=""8"" ss:Bold=""1""/>"
startExcelXML &= vbNewLine & "<Interior ss:Color=""#C0C0C0"" ss:Pattern=""Solid""/>"
startExcelXML &= vbNewLine & "</Style>"

startExcelXML &= vbNewLine & " <Style ss:ID=""Reg"">"
startExcelXML &= vbNewLine & " <Font " + "x:Family=""Swiss"" ss:Bold""0""/>"
startExcelXML &= vbNewLine & " </Style>"

startExcelXML &= vbNewLine & "</Styles>"

'write the header to the file
doc.WriteLine(startExcelXML)


'write one sheet per table
For Each tab As DataTable In source.Tables
Dim sheetname As String = "<Worksheet ss:Name="
sheetname &= Microsoft.VisualBasic.Chr(34)
sheetname &= tab.TableName.Trim
sheetname &= Microsoft.VisualBasic.Chr(34)
sheetname &= ">"
doc.WriteLine(sheetname)

doc.WriteLine("<Table>")

'write the column headers
doc.WriteLine("<Row>")
For Each col As DataColumn In tab.Columns
doc.Write("<Cell ss:StyleID=""ColHeader""><Data ss:Type=""String"">")
doc.Write(col.ColumnName)
doc.WriteLine("</Data></Cell>")
Next
doc.WriteLine("</Row>")


'write the table
For Each row As DataRow In tab.Rows
doc.WriteLine("<Row>")

'Dim i As Integer
For i As Integer = 0 To tab.Columns.Count - 1
doc.Write("<Cell ss:StyleID=""Reg""><Data ss:Type=""String"">")
doc.Write(row.Item(i))
doc.WriteLine("</Data></Cell>")
Next

doc.WriteLine("</Row>")
Next


doc.WriteLine("</Table>")
doc.WriteLine("</Worksheet>")
Next

doc.WriteLine("</Workbook>")
doc.Close()

End Sub


this can be opened in excel. You will have to add your own formating to make the sheet look like you want, to do that just make changes, save it and open it and see what it did to the tags. Then make your code do the same.

Hope this helps

Kevin
GeneralRe: data from VB.NET to MS Excel Pin
Johan Hakkesteegt16-Nov-06 7:32
Johan Hakkesteegt16-Nov-06 7:32 
GeneralRe: data from VB.NET to MS Excel Pin
Kevin Nicol16-Nov-06 8:00
Kevin Nicol16-Nov-06 8:00 
QuestionError('20527' sql server error) while connecting ADO recodset to crystal report Pin
Ramesh N G16-Nov-06 3:19
Ramesh N G16-Nov-06 3:19 
Questionselect case Pin
charchabil0316-Nov-06 2:05
charchabil0316-Nov-06 2:05 
AnswerRe: select case Pin
nlarson1116-Nov-06 3:57
nlarson1116-Nov-06 3:57 
AnswerRe: select case [modified] Pin
Yona Low16-Nov-06 4:17
Yona Low16-Nov-06 4:17 
GeneralRe: select case Pin
nlarson1116-Nov-06 4:34
nlarson1116-Nov-06 4:34 
GeneralRe: select case Pin
Yona Low16-Nov-06 4:44
Yona Low16-Nov-06 4:44 
Questionhow to logoff using Windows Service Pin
BSRK16-Nov-06 1:39
BSRK16-Nov-06 1:39 
AnswerRe: how to logoff using Windows Service Pin
Dave Sexton16-Nov-06 3:16
Dave Sexton16-Nov-06 3:16 
AnswerRe: how to logoff using Windows Service Pin
Dave Sexton16-Nov-06 3:43
Dave Sexton16-Nov-06 3:43 
GeneralRe: how to logoff using Windows Service Pin
Dave Kreskowiak16-Nov-06 4:15
mveDave Kreskowiak16-Nov-06 4:15 
GeneralRe: how to logoff using Windows Service Pin
Yona Low16-Nov-06 4:21
Yona Low16-Nov-06 4:21 
GeneralRe: how to logoff using Windows Service Pin
Dave Sexton16-Nov-06 19:34
Dave Sexton16-Nov-06 19:34 
GeneralThanks to kulazfuk and Dave Pin
BSRK17-Nov-06 18:41
BSRK17-Nov-06 18:41 
QuestionShared Memory Pin
PlescaSorin16-Nov-06 0:52
PlescaSorin16-Nov-06 0:52 
AnswerRe: Shared Memory Pin
nlarson1116-Nov-06 4:01
nlarson1116-Nov-06 4:01 

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.