首页 新闻 会员 周边

npoi excel 活动区域如何复制

0
[待解决问题]

 npoi指定活动区域之后  怎么进行复制操作

 sheet1.Sheet.SetActiveCellRange(0, 52, 0, 63);

 

类似  微软的自带的office  操作方法 进行复制

 

   object ranobj = DBNull.Value;

                    //设置选择单元格,在复制出来。
                    wsheet.get_Range("A1", "BM51").Copy(ranobj);

                    //全选单元格,全部复制出来。
                    //wsheet.UsedRange.Copy(objMis);
                    //Clipboard.SetDataObject(objMis);
                    IDataObject iData = Clipboard.GetDataObject();

程序员编程日记的主页 程序员编程日记 | 初学一级 | 园豆:6
提问于:2014-02-18 22:58
< >
分享
所有回答(1)
0
 1 public void CopyRange(ISheet sheet, int fromRowIndex, int fromColIndex, int toRowIndex, int toColIndex, bool onlyData)
 2         {
 3             IRow sourceRow = sheet.GetRow(fromRowIndex);
 4             ICell sourceCell = sourceRow.GetCell(fromColIndex);
 5             if (sourceRow != null && sourceCell != null)
 6             {
 7                 IRow changingRow = null;
 8                 ICell changingCell = null;
 9                 changingRow = sheet.GetRow(toRowIndex);
10                 if (changingRow == null)
11                     changingRow = sheet.CreateRow(toRowIndex);
12                 changingCell = changingRow.GetCell(toColIndex);
13                 if (changingCell == null)
14                     changingCell = changingRow.CreateCell(toColIndex);
15 
16                 if (onlyData)//仅数据
17                 {
18                     //对单元格的值赋值
19                     changingCell.SetCellValue(sourceCell.StringCellValue);
20                 }
21                 else         //非仅数据
22                 {
23                     //单元格的编码
24                     //changingCell.Encoding = sourceCell.Encoding;
25                     //单元格的格式
26                     changingCell.CellStyle = sourceCell.CellStyle;
27                     //单元格的公式
28                     //if (sourceCell.CellFormula == "")
29                     changingCell.SetCellValue(sourceCell.StringCellValue);
30                     //else
31                     //    changingCell.SetCellFormula(sourceCell.CellFormula);
32                 }
33             }
34         }

这个是我在 http://npoi.codeplex.com/ 官网上下载的Sample 看的,然后自己写出来的。

你看是否对你有帮助。

宝宝,爸爸爱你 | 园豆:57 (初学一级) | 2014-07-01 23:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册