【问题标题】:Exporting .xlsx/.xls using Closed XML使用封闭 XML 导出 .xlsx/.xls
【发布时间】: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 时做错了。谢谢大家会回答我。最好的问候。

【问题讨论】:

    标签: excel vb.net closedxml


    【解决方案1】:

    使用worksheet.Cell(1, 1)(不带s)访问单个单元格。

    使用Cells() 方法,您可以访问一系列单元格,但为此您需要其他参数,并且没有接受两个整数的重载。错误消息显示了该方法的其他重载,该方法接受两个参数,但不是两个整数,并且无法进行自动转换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 2015-08-05
      • 1970-01-01
      相关资源
      最近更新 更多