最近使用EPPlus 3.1.3操作EXCEL文件的时提示Error saving file E:\\*** ;请哪位大侠帮忙指点下,谢谢!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了最近使用EPPlus 3.1.3操作EXCEL文件的时提示Error saving file E:\\*** ;请哪位大侠帮忙指点下,谢谢!相关的知识,希望对你有一定的参考价值。

C# 语言调用 ,该问题时常碰见,调试也不一定出现,文件都正常,没有被占用等,之后的操作也可能会成功。

是不是上传了文件,检查保存文件的路径对不对

你这个提示没有什么实际意义,提示就说了个“导出”命令在作用于你的图形时发生错误,具体什么错误他没有提示,所以这个问题不好解决了,首先检查一下你的CDR软件,看是只有这一个文件不能正常导出,还是所有CDR文件都不能正常导出了,如果只是这一个文件,你编组所有对象,然后按P,将所有对象居中于画布,然后导出试试。如果不行,且你的CDR文件能够正常打开,建议你另存一下,然后看看另存的那个文件能不能正常导出。如果这两个方法都不能解决,证明你这个CDR文件真的损坏了,没办法了!

希望能帮到你~
参考技术A 你好,这个还是因为你的个人软件问题,建议你重新下载wps,这样才能够使用,满意请采纳,谢谢。

Nuget EPPlus的使用

EPPlus:网站

 

 

Excel Merge Operate

技术分享图片
    public class ExcelMergeOperate
    {
        private static Logger _logger = LogManager.GetCurrentClassLogger();

        #region private method

        private static FileInfo CreateNewExcleFile(string excelPath)
        {
            FileInfo newFile = new FileInfo(excelPath);
            if (newFile.Exists)
            {
                newFile.Delete();  // ensures we create a new workbook
                newFile = new FileInfo(excelPath);
            }
            return newFile;
        }

        private static void AddSheet(ExcelWorksheets fromSheets ,ExcelWorksheets toSheets,string defualtSheetName="")
        {
            foreach (var sheet in fromSheets)
            {
                //check name of worksheet, in case that worksheet with same name already exist exception will be thrown by EPPlus
                string workSheetName = defualtSheetName != null?defualtSheetName:( sheet.Name!=null?sheet.Name : DateTime.Now.ToString("yyyyMMddhhssmmm"));
                foreach (var masterSheet in toSheets)
                {
                    if (sheet.Name == masterSheet.Name)
                    {
                        workSheetName = string.Format("{0}_{1}", workSheetName, DateTime.Now.ToString("yyyyMMddhhssmmm"));
                    }
                }
                sheet.ConditionalFormatting.RemoveAll();
                //add new sheet
                toSheets.Add(workSheetName, sheet);
            }
        }

        private static void MergeExcelsFromList<T>(List<T> date, string mergeExcelPath, string defualtSheetName = "date", bool create = false) where T : class
        {

            try
            {
                FileInfo newFile = create ? CreateNewExcleFile(mergeExcelPath) : new FileInfo(mergeExcelPath); ;
                using (ExcelPackage masterPackage = new ExcelPackage(newFile))
                {
                    //Create the Worksheet
                    var sheet = masterPackage.Workbook.Worksheets.Add(defualtSheetName);
                    //Create the format object to describe the text file
                    var format = new ExcelTextFormat();
                    format.TextQualifier = ";
                    format.SkipLinesBeginning = 2;
                    format.SkipLinesEnd = 1;
                    //Now read the file into the sheet. Start from cell A1. Create a table with style 27. First row contains the header.
                    Console.WriteLine("Load the text file...");
                    //Load directories ordered by Name...
                    var range = sheet.Cells["A1"].LoadFromCollection(
                        from line in date
                        select line,
                        true, TableStyles.Medium9);
                    masterPackage.Save();
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
            }
        }

        #endregion


        #region public method

        public static void MergeExcelsFromMutiExcelPath(List<string> excelPaths,string mergeExcelPath,bool create=false)
        {
            try
            {
                //excelPaths = new string[] { @"D:\Jimmy Team Project\Doc\2017-11-20日报表汇总\fang_Westwin Report _GlasessShop.xlsx", @"D:\Jimmy Team Project\Doc\2017-11-20日报表汇总\总结new2017-11-20.xlsx" };
                //mergeExcelPath = @"D:\result.xlsx";
                FileInfo newFile = create ? CreateNewExcleFile(mergeExcelPath): new FileInfo(mergeExcelPath);
                using (ExcelPackage masterPackage = new ExcelPackage(newFile))
                {
                    foreach (var file in excelPaths)
                    {

                        using (ExcelPackage pckg = new ExcelPackage(new FileInfo(file)))
                        {
                            AddSheet(pckg.Workbook.Worksheets, masterPackage.Workbook.Worksheets);
                        }
                    }
                    masterPackage.Save();
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
            }
        }

        public static void MergeExcelsFromMutiExcelStream(List<Stream> streams, string mergeExcelPath, bool create = false)
        {
            try
            {
                FileInfo newFile = create ? CreateNewExcleFile(mergeExcelPath) : new FileInfo(mergeExcelPath);
                using (ExcelPackage masterPackage = new ExcelPackage(newFile))
                {
                    foreach (var stream in streams)
                    {
                        using (ExcelPackage pckg = new ExcelPackage(stream))
                        {
                            AddSheet(pckg.Workbook.Worksheets, masterPackage.Workbook.Worksheets);
                        }
                    }
                    masterPackage.Save();
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
            }
        }

        

        public static void MergeExcelsFromCSVFile<T, M>(string csvPath, string mergeExcelPath, string defualtSheetName = "csv", bool create = false, string csvDelimiter = ",") where T : class where M : CsvClassMap<T>
        {
            using (FileStream fs = new FileStream(csvPath, FileMode.Open, FileAccess.Read))
            {
                List<T> date = CSVHelper<T>.GetEntityFromCSV<M>(fs, csvDelimiter);
                MergeExcelsFromList(date, mergeExcelPath, defualtSheetName, create);
            }
        }

        public static void MergeExcelsFromCSVFile<T>(string csvPath, string mergeExcelPath, string defualtSheetName = "csv", bool create = false, string csvDelimiter = ",") where T : class
        {
            using (FileStream fs = new FileStream(csvPath, FileMode.Open, FileAccess.Read))
            {
                List<T> date = CSVHelper<T>.GetEntityFromCSV(fs, csvDelimiter);
                MergeExcelsFromList(date, mergeExcelPath, defualtSheetName, create);
            }
        }

        #endregion


    }
View Code

 

以上是关于最近使用EPPlus 3.1.3操作EXCEL文件的时提示Error saving file E:\\*** ;请哪位大侠帮忙指点下,谢谢!的主要内容,如果未能解决你的问题,请参考以下文章

使用Epplus操作Excel,但是它支持xls格式吗?我试过xlsx的可以

C# NPOI导出Excel和EPPlus导出Excel比较

DotNetZip生成多个excel文件损坏-踩坑填坑系列

使用 epplus 从 blob 触发 azure 函数访问 excel 文件

使用 EPPlus 将 DataTable 导出到 Excel

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