Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27376

VS 2008 Allowing users to select where to save.

$
0
0
I am using a Streamwriter to write a datagridView to An excel file. I have that working properly, but i just need help letting the user specify a save spot. I figured itd be better here than in Office Development, since i have the office part working.
Here is the code for the writer.
Code:

Private Sub btnExport_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
        Dim fs As New IO.StreamWriter("C:\Users\Derpy\Documents\exported.xls", False)
        fs.WriteLine("<?xml version=""1.0""?>")
        fs.WriteLine("<?mso-application progid=""Excel.Sheet""?>")
        fs.WriteLine("<ss:Workbook xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet"">")
        fs.WriteLine("    <ss:Styles>")
        fs.WriteLine("        <ss:Style ss:ID=""1"">")
        fs.WriteLine("          <ss:Font ss:Bold=""1""/>")
        fs.WriteLine("        </ss:Style>")
        fs.WriteLine("    </ss:Styles>")
        fs.WriteLine("    <ss:Worksheet ss:Name=""Sheet1"">")
        fs.WriteLine("        <ss:Table>")
        For x As Integer = 0 To DataGridView.Columns.Count - 1
            fs.WriteLine("            <ss:Column ss:Width=""{0}""/>", DataGridView.Columns.Item(x).Width)
        Next
        fs.WriteLine("            <ss:Row ss:StyleID=""1"">")
        For i As Integer = 0 To DataGridView.Columns.Count - 1
            fs.WriteLine("                <ss:Cell>")
            fs.WriteLine(String.Format("                  <ss:Data ss:Type=""String"">{0}</ss:Data>", DataGridView.Columns.Item(i).HeaderText))
            fs.WriteLine("                </ss:Cell>")
        Next
        fs.WriteLine("            </ss:Row>")
        For intRow As Integer = 0 To DataGridView.RowCount - 2
            fs.WriteLine(String.Format("            <ss:Row ss:Height =""{0}"">", DataGridView.Rows(intRow).Height))
            For intCol As Integer = 0 To DataGridView.Columns.Count - 1
                fs.WriteLine("                <ss:Cell>")
                fs.WriteLine(String.Format("                  <ss:Data ss:Type=""String"">{0}</ss:Data>",DataGridView.Item(intCol, intRow).Value.ToString))
                fs.WriteLine("                </ss:Cell>")
            Next
            fs.WriteLine("            </ss:Row>")
        Next
        fs.WriteLine("        </ss:Table>")
        fs.WriteLine("    </ss:Worksheet>")
        fs.WriteLine("</ss:Workbook>")
        fs.Close()
    End Sub


Viewing all articles
Browse latest Browse all 27376

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>