2009-12-14 251 views
0

我已經使用微軟Excel表格..我跌倒了不同的值在Excel表格中沒有問題.. 但我倒了一些數字列這樣(00023785678)..在這個列第一零時,無法得到它.. 所以我去改變文本的單元格格列..Excel單元格格式文本更改

如何在Vb.net的代碼創建..我已經有下降的Excel工作表這種方法...

 Dim oXL As Excel.Application 
      Dim oWB As Excel.Workbook 
      Dim oSheet As Excel.Worksheet 
      Dim columnrange = oSheet.Columns 
      Dim therange = oSheet.UsedRange 
      ' Dim wb As Microsoft.Office.Interop.Excel.Workbook 
      ''Dim style As Microsoft.Office.Interop.Excel.Style 
      oXL = CreateObject("Excel.Application") 
      oXL.Visible = True 
      oWB = oXL.Workbooks.Add 
      oSheet = oWB.ActiveSheet 
      'oXL.Selection.num() 
      oXL.Selection.NumberFormat = "Text" 

      For c As Integer = 0 To dt.Columns.Count - 1 
       oSheet.Cells(1, c + 1).Value = dt.Columns(c).ColumnName 

      Next 
      For rCnt As Int16 = 2 To therange.Rows.Count 
       Dim rowArray(therange.Columns.Count) As String 
       For cCnt As Int16 = 1 To therange.Columns.Count 
        Dim Obj = CType(therange.Cells(rCnt, cCnt), Excel.Range) 
        Dim celltext As String 
        celltext = Obj.Value.ToString 
        rowArray((cCnt - 1)) = celltext 

       Next 
      Next 

      For r As Integer = 0 To dt.Rows.Count - 1 
       For c As Integer = 0 To dt.Columns.Count - 1 
        oSheet.Cells(r + 2, c + 1).Value = dt.Rows(r)(c) 
        oSheet.Cells(r + 2, c + 1).numberformat = "0" 
       Next 
      Next 
      'With oWB 
      ' .Cells(seriesName.GetUpperBound(0) + 7, 3).numberformat = "#.00" 
      ' .Cells(seriesName.GetUpperBound(0) + 7, 5).numberformat = "0" 
      'End With 


      'With oSheet.Range("A1", "ZZ1") 
      ' .Font.Bold = True 
      ' .VerticalAlignment = Excel.XlVAlign.xlVAlignCenter 
      ' .HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter 
      ' .EntireColumn.AutoFit() 
      ' .EntireRow.AutoFit() 
      'End With 

      Dim FirstRow As Long 
      Dim SecentRow As Long 
      Dim ThirdRow As Long 
      With oSheet.Range("A1", "BD1") 
       FirstRow = 1 
       SecentRow = 2 
       ThirdRow = 3 
       .Rows(0 + 1).EntireRow.Insert() 
       .Rows(0 + 1).EntireRow.Insert() 
       .Rows(0 + 1).EntireRow.Insert() 
       .Font.Bold = True 
       .VerticalAlignment = Excel.XlVAlign.xlVAlignCenter 
       .HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter 
       .EntireColumn.AutoFit() 
       .EntireRow.AutoFit() 

       '.EntireRow.TextToColumns() 


       .Offset.Justify() 
       .Offset.BorderAround() 
       .Offset.WrapText = True 
       .Offset.Select() 
      End With 

但是現在。我不拿到答... 來請幫我...

回答

4

將您希望視爲文本的單元格中的值前綴爲前導單引號'。這會強制Excel將單元格視爲文本,並且單引號在表單中將不可見。

1
oSheet.Range("A1", "BD1").NumberFormat = "@" 

這會做到這一點。