当前位置: 代码迷 >> C# >> Epplus 设置excel 页边距 及多文件归拢
  详细解决方案

Epplus 设置excel 页边距 及多文件归拢

热度:390   发布时间:2016-04-28 08:20:30.0
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)

 

1楼kljsa
查看白银、原油、铜双向交易投资赚钱技巧,推荐访问:金十数据名师讲解
  相关解决方案