运算符'>='未定义为类型 'Integer' 和 'closedxml.excel.ixlrow



我试图使用 ClosedXML 每 13 行添加分页符,但我无法解决这个问题

Dim xrow As Integer = 0
Do Until xrow >= ws.LastRowUsed()
   ws.PageSetup.AddHorizontalPageBreak(xrow)
   xrow += 13
Loop

我收到错误,因为

运算符">="未定义为类型"整数"和 'closedxml.excel.ixlrow

在你的代码中:

直到 xrow>= ws。LastRowUsed()
互联网服务提供商LastRowUsed() '<-- 将指向行而不是行号,因此它无法与整数值进行比较,这就是为什么您在运行代码时收到此类错误消息的原因。 因此,将其更改为:

ws.LastRowUsed().RowNumber() '<-- will give you the specific row number

因此,您的代码将如下所示:

Dim xrow As Integer = 0
Do Until xrow >= ws.LastRowUsed().RowNumber()
   ws.PageSetup.AddHorizontalPageBreak(xrow)
   xrow += 13
Loop

最新更新