【问题标题】:stringWrite - Length can't be less than zerostringWrite - 长度不能小于零
【发布时间】:2012-10-18 20:02:27
【问题描述】:

我正在将 datagrid 数据导出到 excel 中,导出功能正常工作,直到我修复了标题行,现在此行的导出函数中出现错误:

sAux = stringWrite.ToString().Substring(0, stringWrite.ToString().IndexOf("<tr"));

似乎 stringWrite 为空,因此出现警告消息:

System.ArgumentOutOfRangeException: 长度不能小于零。

【问题讨论】:

    标签: stringwriter


    【解决方案1】:

    这意味着IndexOf() 返回 -1。 IOW,它没有找到&lt;tr。你不能接受SubString(0, -1)

    声明一个变量,并将IndexOf()的结果赋值给该变量,并确保找到了你想要的子字符串:

    Idx = stringWrite.ToString().IndexOf("<tr");
    if Idx > -1 
    {
       sAux = ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 1970-01-01
      • 2022-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多