Created
June 8, 2013 22:07
-
-
Save pradesa/5736771 to your computer and use it in GitHub Desktop.
Use XML, Deskripsi tiap row Menyusul
Source : Mbah google ( authornya lupa )
di modifikasi sedikit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Public Shared Sub _ExporttoExcel(ByVal _DataGridView As DataGridView, ByVal _Form As Form) | |
| Dim Excel As New IO.StreamWriter(Application.StartupPath & "\Export.xls", False) | |
| Dim _Tmp As String = _Form.Text | |
| Dim _totalRow As Integer = 0 | |
| Excel.WriteLine("<?xml version=""1.0""?>") | |
| Excel.WriteLine("<?mso-application progid=""Excel.Sheet""?>") | |
| Excel.WriteLine("<ss:Workbook xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet"">") | |
| Excel.WriteLine(" <ss:Styles>") | |
| Excel.WriteLine(" <ss:Style ss:ID=""1"">") | |
| Excel.WriteLine(" <ss:Font ss:Bold=""0""/>") | |
| Excel.WriteLine(" </ss:Style>") | |
| Excel.WriteLine(" </ss:Styles>") | |
| Excel.WriteLine(" <ss:Worksheet ss:Name=""Export"">") | |
| Excel.WriteLine(" <ss:Table>") | |
| With _DataGridView | |
| _totalRow = .Rows.Count | |
| For z As Integer = 0 To .Columns.Count - 1 | |
| Excel.WriteLine(" <ss:Column ss:Width=""{0}""/>", .Columns.Item(z).Width) | |
| Next | |
| Excel.WriteLine(" <ss:Row ss:StyleID=""1"">") | |
| For i As Integer = 0 To .Columns.Count - 1 | |
| Excel.WriteLine(" <ss:Cell>") | |
| Excel.WriteLine(String.Format("<ss:Data ss:Type=""String"">{0}</ss:Data>", .Columns(i).Name)) | |
| Excel.WriteLine(" </ss:Cell>") | |
| Next | |
| Excel.WriteLine(" </ss:Row>") | |
| For x = 0 To .Rows.Count - 1 | |
| _Form.Text = _Tmp & " Export to Excel ( " & x & " / " & _totalRow & ")" | |
| Excel.WriteLine(" <ss:Row ss:StyleID=""1"">") | |
| For y = 0 To .Columns.Count - 1 | |
| Excel.WriteLine(" <ss:Cell>") | |
| Excel.WriteLine(String.Format("<ss:Data ss:Type=""String"">{0}</ss:Data>", .Rows(x).Cells(y).Value)) | |
| Excel.WriteLine(" </ss:Cell>") | |
| Next | |
| Excel.WriteLine(" </ss:Row>") | |
| Next | |
| End With | |
| Excel.WriteLine(" </ss:Table>") | |
| Excel.WriteLine(" </ss:Worksheet>") | |
| Excel.WriteLine("</ss:Workbook>") | |
| Excel.Close() | |
| Dim FileNameTmp As String = "c:\Export" & Format(Now, "ddMMyyyyhhmmss") & ".xls" | |
| System.IO.File.Copy(Application.StartupPath & "\Export.xls", FileNameTmp) | |
| _Form.Text = _Form.Text & " Selesai, Proses Buka File" | |
| Threading.Thread.Sleep(100) | |
| System.Diagnostics.Process.Start(FileNameTmp) | |
| _Form.Text = _Tmp | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment