469,337 Members | 6,011 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,337 developers. It's quick & easy.

VB.NET: Problem with charset setting when export to Excel

VietPP
17
Hi all,

I've asked too much question in this day, hehe.

I'm trying to export my table data in OracleDB to excel. The problem is my charset in database is US7ACSII (using Vietnamese font), when I exprort to excel it's changed to Unicode UTF-8 so all of the characters had lost, text cannot be display correctly.

Is it possible to add a charset setting to code.

Thank you!

I'm using:

Expand|Select|Wrap|Line Numbers
  1. Private Sub saveExcelHA()
  2.         ' This's my loading Flashscreen, you can remove it
  3.         Dim frmStatusMessage As New frmStatus()
  4.         frmStatusMessage.Show("Creating...")
  5.         Dim IsConnecting As Boolean = True
  6.         While IsConnecting
  7.         '-------------------------------------------------
  8.             Try
  9.                 Dim filename As String
  10.                 Dim col, row As Integer
  11.                 Dim ComDset As New DataSet
  12.  
  13.                 Dim SelectStr As String = "select * from myTable"
  14.                 Dim adp As New OracleDataAdapter(SelectStr, Oracnn)
  15.                 ComDset.Reset()
  16.                 adp.Fill(ComDset, "TTbl")
  17.                 If ComDset.Tables.Count < 0 Or ComDset.Tables(0).Rows.Count <= 0 Then
  18.                     Exit Sub
  19.                 End If
  20.                 Dim Excel As Object = CreateObject("Excel.Application")
  21.  
  22.                 If Excel Is Nothing Then
  23.                     MsgBox("Excel is not installed on this machine", MsgBoxStyle.Critical)
  24.                     Return
  25.                 End If
  26.  
  27.                 With Excel
  28.                     .SheetsInNewWorkbook = 1
  29.                     .Workbooks.Add()
  30.                     .Worksheets(1).Select()
  31.  
  32.                     Dim i As Integer = 1
  33.                     For col = 0 To ComDset.Tables(0).Columns.Count - 1
  34.                         .cells(1, i).value = ComDset.Tables(0).Columns(col).ColumnName
  35.                         .cells(1, i).EntireRow.Font.Bold = True
  36.                         i += 1
  37.                     Next
  38.                     i = 2
  39.                     Dim k As Integer = 1
  40.                     For col = 0 To ComDset.Tables(0).Columns.Count - 1
  41.                         i = 2
  42.                         For row = 0 To ComDset.Tables(0).Rows.Count - 1
  43.                             .Cells(i, k).Value = ComDset.Tables(0).Rows(row).ItemArray(col)
  44.                             i += 1
  45.                         Next
  46.                         k += 1
  47.                     Next
  48.                     filename = "c:\DataOut\ExpFile - " & Format(Now(), "yyyyMMdd - hhmmss") & ".xls"
  49.                     .ActiveCell.Worksheet.SaveAs(filename)
  50.                 End With
  51.                 System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
  52.                 Excel = Nothing
  53.                 MsgBox("Done", MsgBoxStyle.Information)
  54.  
  55.                 ' Close opened file.
  56.                 Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
  57.                 For Each i As Process In pro
  58.                     i.Kill()
  59.                 Next
  60.             ' This's my loading Flashscreen, you can remove it
  61.                 IsConnecting = False
  62.             '-------------------------------------------------
  63.             Catch ex As Exception
  64.                 MsgBox(ex.Message, MsgBoxStyle.Critical, "Messages Error")
  65.                 Throw ex
  66.             End Try
  67.         'This's my loading Flashscreen, you can remove it
  68.         End While
  69.         frmStatusMessage.Close()
  70.         '-------------------------------------------------
  71.     End Sub
Dec 28 '07 #1
0 1394

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by JawzX01 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.