hello guys I asked this question before but I just don't seem to find an answer can someone please tell me what I'm doing wrong in my code because even while I tried every methode on internet no change is ever made on my excel file this my code for changing the color of a cell on an existing excel file
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1. 點擊
Dim ws1 As Microsoft.Office.Interop.Excel.Worksheet。
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
ws1 = xlApp.Workbooks.Open(TextBox1.Text).Worksheets(ComboBox1.SelectedItem)
Dim rangeToFormat As Excel.Range
rangeToFormat = ws1.Cells(6, 5)
rangeToFormat.Interior.Color = ColorTranslator.ToOle(Color.Red)
結束 子
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2. 點擊
Dim xlworkbook As Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
OpenFileDialog1.ShowDialog()
TextBox1.Text = OpenFileDialog1.FileName
xlworkbook = xlApp.Workbooks.Open(TextBox1.Text, 0, True)
For Each xlWorkSheet In xlApp.Sheets
ComboBox1.Items.Add(xlWorkSheet.Name)
下一步 下一步
End Sub
我的代碼要求用戶選擇一個excel檔案,選擇想要作業的作業表,然后點擊一個按鈕來改變單元格(6,5)和其他單元格的顏色,為了使我的代碼更容易理解,我沒有在這里添加。 謝謝你們這些高級的家伙。
uj5u.com熱心網友回復:
試試這個:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1. 點擊
Dim ws1 As Microsoft.Office.Interop.Excel.Worksheet。
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
ws1 = xlApp.Workbooks.Open(TextBox1.Text).Worksheets(ComboBox1.SelectedItem)
Dim rangeToFormat As Excel.Range
rangeToFormat = ws1.Cells(6, 5)
rangeToFormat.Font.Color = RGB(255, 20, 20)
結束 子
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2. 點擊
Dim xlworkbook As Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
OpenFileDialog1.ShowDialog()
TextBox1.Text = OpenFileDialog1.FileName
xlworkbook = xlApp.Workbooks.Open(TextBox1.Text, 0, True)
For Each xlWorkSheet In xlApp.Sheets
ComboBox1.Items.Add(xlWorkSheet.Name)
下一步 下一步
End Sub
uj5u.com熱心網友回復:
對于那些還在尋找答案的人來說,我確實找到了答案,你應該在顏色命令后面加上:
xlWb.Save()
xlApp.Quit()
xlApp = Nothing
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/308307.html
標籤:
上一篇:如何用RESTAPI克隆一個目錄內的倉庫和它們的作者名字?
下一篇:<p>這是我做的一個簡化的例子,以暴露我的問題。我有一些任務<code>doSomeWork()</code>,我使用ExecutorService以多執行緒方式處
