以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]想删除单元格内空行,却改变了单元格字符串长度 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=90147) |
||||
-- 作者:jyh7081 -- 发布时间:2016/9/6 15:56:00 -- [求助]想删除单元格内空行,却改变了单元格字符串长度 下面这段代码是想删除 单元格内 多余空行(单元格内Ctrl+Enter产生的空换行符,如果换行有内容仍保留),执行代码后却改变了其他单元格字符串长度,麻烦版主看看是哪里出了问题? For Each t As Table In Tables For Each r As Row In t.rows For Each c As Col In t.cols Dim ary() As String = cstr(r(c.name)).split(new Char() {chr(10), chr(13)}) Dim str As String = "" For Each s As String In ary If s.trim > "" Then str &= s & vbcrlf End If Next r(c.name) = str Next Next Next |
||||
-- 作者:有点蓝 -- 发布时间:2016/9/6 16:32:00 -- Dim lst As new List(of String) For Each t As Table In Tables For Each r As Row In t.rows For Each c As Col In t.cols lst.Clear Dim lines = r.DataRow.Lines(c.Name) If lines.Count > 1 Then For Each s As String In lines If s.trim > "" Then lst.Add(s) End If Next r(c.name) = String.Join(vbcrlf,lst.ToArray) End If Next Next Next
|
||||
-- 作者:jyh7081 -- 发布时间:2016/9/6 20:10:00 -- 版主,运行代码后,每个单元格字符长度增加2,双击单元格后再离开,长度就会减小2(回到原长度),是什么原因? |
||||
-- 作者:有点蓝 -- 发布时间:2016/9/6 20:52:00 -- 测试没有这种问题,做个例子看看 |
||||
-- 作者:jyh7081 -- 发布时间:2016/9/6 21:08:00 -- 附件:
|
||||
-- 作者:有点蓝 -- 发布时间:2016/9/6 21:34:00 -- Dim lst As new List(of String) For Each t As Table In Tables For Each r As Row In t.rows For Each c As Col In t.cols lst.Clear Dim lines = r.DataRow.Lines(c.Name) If lines.Count > 1 Then For Each s As String In lines If s.trim > "" Then lst.Add(s) End If Next r(c.name) = String.Join(vbcrlf,lst.ToArray) Else r(c.name) = r(c.name).TrimEnd(chr(10),chr(13)) End If Next Next Next |
||||
-- 作者:jyh7081 -- 发布时间:2016/9/6 21:49:00 -- 谢谢版主! |
||||
-- 作者:jyh7081 -- 发布时间:2016/9/6 22:02:00 -- 在例子里行,换到另一项目提示“未设置变量或with块变量” [此贴子已经被作者于2016/9/6 22:11:55编辑过]
|
||||
-- 作者:jyh7081 -- 发布时间:2016/9/7 10:31:00 -- 麻烦版主再给看看。 |
||||
-- 作者:有点蓝 -- 发布时间:2016/9/7 11:00:00 -- 试试 Dim lst As new List(of String) For Each t As Table In Tables For Each r As Row In t.rows For Each c As Col In t.cols If c.IsString Then lst.Clear Dim lines = r.DataRow.Lines(c.Name) If lines.Count > 1 Then For Each s As String In lines If s.trim > "" Then lst.Add(s) End If Next r(c.name) = String.Join(vbcrlf,lst.ToArray) Else r(c.name) = r(c.name).TrimEnd(chr(10),chr(13)) End If End If Next Next Next 或者上传例子
|