Click here to Skip to main content
15,878,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone, I have a sample excel template. I want to write the data from the database on this template. But I am facing such an error. I'm using NPOI library.

C#
IWorkbook workbookMerged;

            using (var file = new FileStream(_importExportHelper.GetFilePath("EXCEL-TEMPLATE-NAME"), FileMode.Open, FileAccess.ReadWrite))
            {
                workbookMerged = new XSSFWorkbook(file); //here
            }


  public string GetFilePath(string source, string type = ".xlsx")
    {
        string sWebRootFolder = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

        var files = new DirectoryInfo(sWebRootFolder + @"\documents\").GetFiles(source + type, SearchOption.TopDirectoryOnly);

        return files.FirstOrDefault().ToString();
    }


What I have tried:

Hi everyone, I have a sample excel template. I want to write the data from the database on this template. But I am facing such an error. I'm using NPOI library.
Posted
Comments
Sandeep Mewara 14-Jan-21 2:41am    
If above set of lines are throwing an error, you need to look at your template. Somewhere there is duplicate column or so which is being expected as unique.

Debug and nail the line of code and then go deep.
Richard Deeming 14-Jan-21 4:48am    
Probably best to report this as a bug in the NPOI GitHub project:
Issues · nissl-lab/npoi · GitHub[^]

You'll need to provide a sample template which you can use to reproduce the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900