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

Free Support Forum - aspose.com

Error While Merging Files

When utilizing your product, I created the following method:


public string Merge(string[] sourceDocuments, string workingDirectory)
{
string convertedFileName = string.Empty;
<span style="color:navy;">try</span>
{
    <span style="color:navy;">if</span> (<span style="color:maroon;">sourceDocuments</span>.<span style="color:maroon;">Count</span>() > <span style="color:#dadada;background:#e6ffff;">0</span>)
    {
        <span style="color:navy;">string</span> <span style="color:maroon;">localFileName</span> = <span style="color:#a65300;">Path</span>.<span style="color:maroon;">GetFileName</span>(<span style="color:maroon;">sourceDocuments</span>.<span style="color:maroon;">First</span>());
        <span style="color:navy;">var</span> <span style="color:maroon;">cachedFileName</span> = <span style="color:#a65300;">Path</span>.<span style="color:maroon;">ChangeExtension</span>(<span style="color:#a65300;">Path</span>.<span style="color:maroon;">Combine</span>(<span style="color:maroon;">workingDirectory</span>, <span style="color:maroon;">localFileName</span>), <span style="background:#ffffe6;">"TMP"</span>);
        <span style="color:navy;">var</span> <span style="color:maroon;">mergedFileName</span> = <span style="color:#a65300;">Path</span>.<span style="color:maroon;">ChangeExtension</span>(<span style="color:#a65300;">Path</span>.<span style="color:maroon;">Combine</span>(<span style="color:maroon;">workingDirectory</span>, <span style="color:maroon;">localFileName</span>), <span style="background:#ffffe6;">"XLSM"</span>);
        <span style="color:#a65300;">CellsHelper</span>.<span style="color:maroon;">MergeFiles</span>(<span style="color:maroon;">sourceDocuments</span>, <span style="color:maroon;">cachedFileName</span>, <span style="color:maroon;">mergedFileName</span>);
        <span style="color:#a65300;">File</span>.<span style="color:maroon;">Delete</span>(<span style="color:maroon;">cachedFileName</span>);

        <span style="color:maroon;">convertedFileName</span> = <span style="color:navy;">this</span>.<span style="color:maroon;">Convert</span>(<span style="color:maroon;">mergedFileName</span>, <span style="color:maroon;">workingDirectory</span>);
    }
}
<span style="color:navy;">catch</span> (<span style="color:#a65300;">Exception</span> <span style="color:maroon;">ex</span>)
{
    <span style="color:navy;">throw</span>;
}

<span style="color:navy;">return</span> <span style="color:maroon;">convertedFileName</span>;

}


I received the following error on the exception:

System.InvalidOperationException was caught
_HResult=-2146233079
_message=This is not a structured storage file.
HResult=-2146233079
IsTransient=false
Message=This is not a structured storage file.
Source=Aspose.Cells
StackTrace:
at . …ctor(BinaryReader )
at . . (Stream )
at . …ctor(String )
at . . (String[] )
at . .Combine(String[] , String , String )
at Aspose.Cells.CellsHelper.MergeFiles(String[] files, String cachedFile, String destFile)
at SNL.Services.Documents.Excel.AsposeConversionEngine.Merge(String[] sourceDocuments, String workingDirectory) in …\AsposeConversionEngine.cs:line 53
InnerException:

Note that the full file name was excised in that last line of the stack trace.

Why would it be complaining about a Structured Storage file? The files in question are excel files, and I’m just changing the extension to be .xlsm purely for local use.

Thoughts?

Hi,

Thanks for your posting and using Aspose.Cells.

Please download and try the latest version: Aspose.Cells for .NET (Latest Version) and see if fixes this issue.

If your problem still occurs, then please provide us your source Excel file causing this exception. We will look into it and help you asap.

Hi,

Thanks for using Aspose.Cells.

This feature only supports xls files. Please use Workbook.Combine() method.

Please also see the following documentation article that explains how to combine multiple workbooks into a single workbook.


When you say only xls files, does it support xslx files? For that’s what all of these are… the naming is only for convenience.

Hi Charles,


Please use the Workbook.Combine method as suggested by Shakeel in his previous response. The said method supports both XLS & XLSX formats. Please note, both extensions correspond to the spreadsheet format however both differ in structure. XLS file format was used by MS Excel till the revision of 2007, whereas XLSX is the default Excel 2007 and later workbook format. In reality XLSX is a ZIP compressed archive with a directory structure of XML text documents.

Please feel free to contact us back in case you need further assistance with Aspose APIs.

Thanks for your response. I do know the difference between XLS and XLSX files- which was indeed one of the reasons I ask for clarification.


I’m concerned about the overhead of opening each workbook (this is a merge of several) as a workbook object, which was the reason that I was utilizing the merge method. I’ll test the two and report back if I have any further questions or problems.

Thanks!

Hi Charles,

Thanks for your posting and using Aspose.Cells.

CellsHelper.MergeFiles() can only be used for XLS files. You cannot use it for XLSX files. Therefore, we suggest you to use Combine() method that can be used for both XLS and XLSX formats.

Thank you for the clarification!