找回密码
 立即注册

QQ登录

只需一步,快速开始

zhou_sir
论坛元老   /  发表于:2012-6-28 16:19  /   查看:7146  /  回复:9
请问如何清除当前sheet中的所有数据(行头、列头保留)?(版本:V4.0 .net web)   
4.0里好像没有ClearRange()方法,通过摸索发现通过循环行列赋值可以清除数据,但单元格背景、边框等格式没清除,不知道4.0版本里有没有相关的方法?

9 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2012-6-28 16:47:00
沙发
回复 1楼zhou_sir的帖子

1.前台清除方法:

  1.        //遍历循环清除
  2.         function ergClear() {
  3.             var spread = this.document.getElementById("<%=this.FpSpread1.ClientID%>");
  4.             for (var i = 0; i < spread.GetRowCount(); i++) {
  5.                 for (var j = 0; j < spread.GetColCount(); j++) {
  6.                     var cell = spread.GetCellByRowCol(i, j);
  7.                     cell.innerText = "";
  8.                 }
  9.             }
  10.         }
复制代码

2.还可以参考:Spread 客户端 js 方法 Clear 和 ClearSelection 方法。
回复 使用道具 举报
zhou_sir
论坛元老   /  发表于:2012-6-28 17:00:00
板凳
谢谢,我现在做的是一个可供项目所有报表统一调用的报表处理方案,需要写成后台方法。现在通过循环然后执行如下方法实现了,但感觉效率上肯定一般:
                    curSheetView.SetText(dataRowIndex, dataColIndex, &quot;&quot;);
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetBorder();
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetBackColor();
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetBackground();
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetFont();
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetForeColor();
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetHorizontalAlignment();
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetLocked();
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetTabStop();
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetValue();
                    curSheetView.Cells[dataRowIndex, dataColIndex].ResetVerticalAlignment();
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-6-28 17:08:00
地板
回复 3楼zhou_sir的帖子

尝试以下代码:

  1. this.FpSpread1.Sheets[0].Reset();
复制代码
回复 使用道具 举报
zhou_sir
论坛元老   /  发表于:2012-6-28 17:30:00
5#
4.0版本中没有ReSet()方法。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-6-28 17:49:00
6#
回复 5楼zhou_sir的帖子

不好意思,忽视了版本问题,
1.格式方面可以 Row 和 Column 为单位进行重置,如重置背景色使用ResetBackColor(),具体可以参考帮助文档。
2.不过,重置单元格数据,需要使用楼主原有的方法。
回复 使用道具 举报
zhou_sir
论坛元老   /  发表于:2012-6-28 18:13:00
7#
好的。谢谢!
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-6-28 18:17:00
8#
回复 使用道具 举报
zhou_sir
论坛元老   /  发表于:2012-6-28 18:21:00
9#
重置不应该使用这个:curSheetView.SetText(dataRowIndex, dataColIndex, &quot;&quot;);应该用:curSheetView.Cells[dataRowIndex, dataColIndex].ResetText();否则会导致后续录入数据时无法录入或无法校验等问题(仅我当前的项目实际情况,供参考)。
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-6-29 17:08:00
10#
正解,根据不同需求可以选择不同方案。:strong:
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部