【发布时间】:2020-11-12 20:10:35
【问题描述】:
我必须将两个列表框导出到 Excel 文件的两列中。我研究了哪种解决方案最合适,然后选择了 ClosedXML。所以我设置了我的保存文件对话框、一个工作簿和一个工作表以便导出它。在代码的开头,我键入了该行以使用 ClosedXML Imports ClosedXML.Excel,并且我正在使用以下代码:
Dim t As Integer
t = CInt(Form10.Label13.Text)
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
Dim workbook As New XLWorkbook()
Dim worksheet = workbook.Worksheets.Add("prova1")
worksheet.Cells(1, 1).Value = "Time"
worksheet.Cells(1, 2).Value = "Heat ratio"
For i = 0 To t
worksheet.Cells(i + 2, 1).Value = Form10.ListBox1.Items(i)
worksheet.Cells(1 + 2, 2).Value = Form10.ListBox2.Items(i)
Next
workbook.Save()
End If
我收到了四个相同的错误,每个工作表都有一个错误。我键入的单元格行。
Error BC30519 Overload resolution failed because no accessible 'Cells' can be called without a narrowing conversion:
'Function Cells(usedCellsOnly As Boolean, includeFormats As Boolean) As IXLCells': Argument matching parameter 'usedCellsOnly' narrows from 'Integer' to 'Boolean'.
'Function Cells(usedCellsOnly As Boolean, includeFormats As Boolean) As IXLCells': Argument matching parameter 'includeFormats' narrows from 'Integer' to 'Boolean'.
'Function Cells(usedCellsOnly As Boolean, options As XLCellsUsedOptions) As IXLCells': Argument matching parameter 'usedCellsOnly' narrows from 'Integer' to 'Boolean'.
'Function Cells(usedCellsOnly As Boolean, options As XLCellsUsedOptions) As IXLCells': Argument matching parameter 'options' narrows from 'Integer' to 'XLCellsUsedOptions'.
我不明白错误可能出在哪里。我四处搜索,但在线提供的代码仅适用于 C#。我是一个初学者程序员,也许我在从 C#“翻译”到 VB.net 时做错了。谢谢大家会回答我。最好的问候。
【问题讨论】: