Epplus 设置excel 页边距 及多文件合并

1:使用epplus合并多个excel文件到同一excel的不同sheet页中

  

 private static bool MergeExcel(string _stFilePath, List<string> _listFiles, string _stSaveFileName)
        {
            ExcelPackage epMergeFile = new ExcelPackage();
            bool result = true;
            try
            {
                string stSheetName = string.Empty;
                foreach (string item in _listFiles)
                {
                    if (!FileIsHave(_stFilePath + "\\" + item)) continue;
                    FileInfo newFile = new FileInfo(_stFilePath + "\\" + item);
                    //开启
                    using (ExcelPackage pck = new ExcelPackage(newFile))
                    {
                        //设定ExcelWorkBook
                        ExcelWorkbook workBook = pck.Workbook;
                        if (workBook != null)
                        {
                            if (workBook.Worksheets.Count > 0)
                            {
                               //设置excel表格的页边距
                                //workBook.Worksheets[1].PrinterSettings.TopMargin = 10M / 2.54M;
                                stSheetName = item.Substring(0, item.LastIndexOf('.'));
                                epMergeFile.Workbook.Worksheets.Add(stSheetName, workBook.Worksheets[1]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                Debug.WriteLine("合并文件失败:" + ex.Message);
                throw new Exception("合并文件失败!");
            }

            if (result)
            {
                string stFile = _stFilePath + "\\" + _stSaveFileName;
                epMergeFile.SaveAs(new FileInfo(stFile));
                epMergeFile.Dispose();
            }

            return result;
        }

  2:设置excel文件sheet页的 页边距(使用epplus)

 

转载于:https://www.cnblogs.com/xiaojt/p/5337613.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值