Ami2
Ami2
CC#
Created by Ami2 on 12/17/2023 in #help
I'm currently grappling with an issue while merging two Excel workbooks (`array1` and `array2`)
@canton7 note I'm call the result here
var bytes = _service.MergeExcelWorksheets();

if (bytes == null)
return null;

var fileStream = new MemoryStream(bytes);

var contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
var fileDownloadName = string.Format("test{0}.xlsx", DateTime.Now.ToString("yyyyMMdd"));

fileStream.Position = 0;
var fsr = new FileStreamResult(fileStream, contentType);
fsr.FileDownloadName = fileDownloadName;
var bytes = _service.MergeExcelWorksheets();

if (bytes == null)
return null;

var fileStream = new MemoryStream(bytes);

var contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
var fileDownloadName = string.Format("test{0}.xlsx", DateTime.Now.ToString("yyyyMMdd"));

fileStream.Position = 0;
var fsr = new FileStreamResult(fileStream, contentType);
fsr.FileDownloadName = fileDownloadName;
11 replies
CC#
Created by Ami2 on 12/17/2023 in #help
I'm currently grappling with an issue while merging two Excel workbooks (`array1` and `array2`)
I already this package1.Save(); after Iterate through sheets in workbook2 but nothing changes
11 replies
CC#
Created by Ami2 on 12/17/2023 in #help
I'm currently grappling with an issue while merging two Excel workbooks (`array1` and `array2`)
And the solution bellow return just the sheets of the first workbook but the sheets of the second one not created
private byte[] MergeExcelWorksheets(byte[] array1, byte[] array2)
{
using (MemoryStream ms1 = new MemoryStream(array1))
using (MemoryStream ms2 = new MemoryStream(array2))
using (ExcelPackage package1 = new ExcelPackage(ms1))
using (ExcelPackage package2 = new ExcelPackage(ms2))
{
var workbook1 = package1.Workbook;
var workbook2 = package2.Workbook;

// Iterate through sheets in workbook2
foreach (var sourceSheet in workbook2.Worksheets)
{
if (!workbook1.Worksheets.Any(sheet => sheet.Name == sourceSheet.Name))
{
// Clone the sheet and add it to workbook1
var clonedSheet = workbook1.Worksheets.Add(sourceSheet.Name, sourceSheet);
}
}

return ms1.ToArray();
}
}
private byte[] MergeExcelWorksheets(byte[] array1, byte[] array2)
{
using (MemoryStream ms1 = new MemoryStream(array1))
using (MemoryStream ms2 = new MemoryStream(array2))
using (ExcelPackage package1 = new ExcelPackage(ms1))
using (ExcelPackage package2 = new ExcelPackage(ms2))
{
var workbook1 = package1.Workbook;
var workbook2 = package2.Workbook;

// Iterate through sheets in workbook2
foreach (var sourceSheet in workbook2.Worksheets)
{
if (!workbook1.Worksheets.Any(sheet => sheet.Name == sourceSheet.Name))
{
// Clone the sheet and add it to workbook1
var clonedSheet = workbook1.Worksheets.Add(sourceSheet.Name, sourceSheet);
}
}

return ms1.ToArray();
}
}
11 replies
CC#
Created by Ami2 on 12/17/2023 in #help
I'm currently grappling with an issue while merging two Excel workbooks (`array1` and `array2`)
Seems I'm close to find the solution but the only problem I facing now is If I'm returing the right data return package1.GetAsByteArray();
11 replies
CC#
Created by Ami2 on 12/17/2023 in #help
I'm currently grappling with an issue while merging two Excel workbooks (`array1` and `array2`)
I didn't find any
11 replies