按照3个sheet分割代码如下,仅作参考,注意实际代码还需要考虑总sheet数不是3的倍数,加以判断
- void segmentationWorkbooke(string filename)
- {
- FpSpread fpSpread = new FpSpread();
- fpSpread.Open(filename);
- int pagesize = 3;
- for (int i = 0; i < fpSpread.Sheets.Count; i += pagesize)
- {
- FpSpread fp = new FpSpread();
- fp.Sheets.Add(fpSpread.Sheets[i].Clone());
- fp.Sheets.Add(fpSpread.Sheets[i + 1].Clone());
- fp.Sheets.Add(fpSpread.Sheets[i + 2].Clone());
- fp.Save(filename.Substring(0, filename.Length - 4) + "_" + i.ToString() + ".xml", false);
- }
- }
复制代码
合并的话也是类似的操作就行,循环去加载多个文件
- void openXmls(string[] files) {
- fpSpread1.Sheets.Clear();
- foreach(string file in files)
- {
- FpSpread fp = new FpSpread();
- fp.Open(file);
- fpSpread1.Sheets.AddRange(fp.Sheets);
- }
- }
复制代码
|