1
我有一個datagrid視圖,我導入此數據網格中的Excel值,但我看不到單元格的顏色。這是我的代碼和圖片。VB.Net datagrid導入excel單元格顏色
我怎樣才能將顏色從Excel傳遞到數據網格?
[
Dim cmb As New DataGridViewComboBoxColumn()
cmb.HeaderText = "Colum1"
cmb.Name = "cmb"
cmb.Items.Add("Select for Main Plot")
cmb.Items.Add("Select")
DataGridView1.Columns.Add(cmb)
Dim conn As OleDbConnection
Dim dta As OleDbDataAdapter
Dim dts As DataSet
Dim excel As String
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "All Files (*.*)|*.*|Excel files (*.xlsx)|*.xlsx|CSV Files (*.csv)|*.csv|XLS Files (*.xls)|*xls"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
End If
Dim fi As New FileInfo(OpenFileDialog.FileName)
Dim FileName As String = OpenFileDialog.FileName
excel = fi.FullName
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties=Excel 12.0;")
dta = New OleDbDataAdapter("Select * From [Sayfa1$]", conn)
dts = New DataSet
dta.Fill(dts, "[Sayfa1$]")
DataGridView1.DataSource = dts
DataGridView1.DataMember = "[Sayfa1$]"
conn.Close()
OleDbConnection有望從您的Excel文件讀取數據,而不是單元格格式並將其傳輸到DataGridView。你自己在這裏。 – Steve
你在這裏提出什麼建議 – Emrah