We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

NullReferenceException on WorkBook.Combine

When I try to Save a Workbook after combining 2 different files the component throws a “Object reference not set to an instance of an object” with the following stack trace:
at xabb58b8f2887ff8e.x50d9ace66d7842b0.x6e768110e4d8667f(FormatCondition x4d16ee7ee4ba1146, String xcde081a7199c823a)
at xabb58b8f2887ff8e.x50d9ace66d7842b0.xbf8e11070c9420e9(XmlTextWriter xbdfb620b7167944b, FormatCondition x4d16ee7ee4ba1146, String xcde081a7199c823a, Int32 x32e9b596b865a6b6)
at xabb58b8f2887ff8e.x50d9ace66d7842b0.x869d8fa22bbd2c1b(XmlTextWriter xbdfb620b7167944b)
at xabb58b8f2887ff8e.x50d9ace66d7842b0.x6210059f049f0d48(XmlTextWriter xbdfb620b7167944b)
at xabb58b8f2887ff8e.xb440dd60010e3cc4.x7ef0a1369079a9c7(x6fc54f8ba8aae1d4 xd9171314ec0b2957)
at xabb58b8f2887ff8e.xb440dd60010e3cc4.xc228659948392f83(x6fc54f8ba8aae1d4 xd9171314ec0b2957)
at xabb58b8f2887ff8e.xb440dd60010e3cc4.x6b3641eeb6a37b82()
at xabb58b8f2887ff8e.xb440dd60010e3cc4.x6210059f049f0d48()
at Aspose.Cells.Workbook.Save(Stream stream, FileFormatType fileFormatType)
at Aspose.Cells.Workbook.Save(String fileName, FileFormatType fileFormatType)

Files are also attached, the original csv file along with the two xlsx files to combine.

This is the code:

                string origLoc = (string)mngr.Parameters["original"];
                FileFormatType saveType = FileFormatType.Excel2007Xlsx;
                ArrayList files = (ArrayList)mngr.Parameters["files"];
                string outputLoc = (string)mngr.Parameters["output"];
                    Workbook orig = new Workbook();
                    if ((origLoc.EndsWith(".csv")) || (origLoc.EndsWith(".CSV")))
                        orig.Open(origLoc, FileFormatType.CSV);
                    else if ((origLoc.EndsWith(".xlsx")) || (origLoc.EndsWith(".XLSX")))
                        orig.Open(origLoc, FileFormatType.Excel2007Xlsx);
                    else if ((origLoc.EndsWith(".xls")) || (origLoc.EndsWith(".XLS")))
                        orig.Open(origLoc, FileFormatType.Excel2003);
                    //combine files into orignal
                    for (int i = 0; i < files.Count; i++)
                        string filepath = (string)files[i];
                        Workbook current = new Workbook();
                        if ((filepath.EndsWith(".csv")) || (filepath.EndsWith(".CSV")))
                            current.Open(filepath, FileFormatType.CSV);
                        else if ((filepath.EndsWith(".xlsx")) || (filepath.EndsWith(".XLSX")))
                            current.Open(filepath, FileFormatType.Excel2007Xlsx);
                        else if ((filepath.EndsWith(".xls")) || (filepath.EndsWith(".XLS")))
                            current.Open(filepath, FileFormatType.Excel2003);

                    if (File.Exists(outputLoc))
                    orig.Save(outputLoc, saveType);//Exception thrown here<a class="attachment" <a class="attachment" href="/uploads/discourse_instance3/23877">Files.zip</a> (16.7 KB)


Thanks for the stack trace and sample code segment.

After seeing your code segment (as you are using Workbook.Open() method which was obsoleted sometimes ago, please use Workbook constructor instead when using newer versions), it looks like you are using some older version of the product. Please try using our latest version/fix: Aspose.Cells for .NET v19.2.x. If you still find the issue with v19.2, kindly do paste sample (runnable) code and attach template files (you did not attach the files in your post, kindly zip the files prior attaching), we will check it soon.

@Amjad_Sahi Thanks - We are using version 4.8.0 of the product, upgrading the component will require a number of source code changes that we cannot make at the moment.
Would you be able to provide a fix or workaround for the version of the component that we are using?

Files.zip (16.7 KB)


Thanks for the sample files.

Since you are using some older version (v4.8.0) of the product, I am afraid, we cannot evaluate your issue using older version. Neither we can include fix in older versions, the fixes are based on latest APIs set only. It might be an issue in the version you are using. There is no workaround for it I am afraid. So, you should upgrade to latest version (e.g Aspose.Cells for .NET v19.2.x) of the product. If you still find any issue with latest version of the product, kindly do create a sample console application (runnable) and post us with the template file and output file, we will check it and figure it out soon.