如何解决使用封闭XML导出.xlsx / .xls
我必须将两个列表框导出到Excel文件的两列中。我研究了哪种解决方案最合适,然后选择了ClosedXML。因此,我设置了savefile对话框,一个工作簿和一个工作表以便导出它。在代码的开头,我键入了该行以便使用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的“翻译”中做错了。谢谢大家会回答我。最好的问候。
解决方法
使用worksheet.Cell(1,1)
(不使用s
)访问单个单元格。
使用Cells()
方法可以访问一定范围的单元格,但是为此您需要其他参数,并且不存在接受两个整数的重载。错误消息显示该方法的其他重载,该重载接受两个参数,但不能接收两个整数,并且无法进行自动转换。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。