Question How to create excel sheet with multiple sheet name based on modules ?

Status
Not open for further replies.

ahmedsalah

Active member
Joined
Sep 26, 2018
Messages
32
Programming Experience
3-5
I work on c# desktop app I cannot export data to excel sheet with multiple tab

meaning multi sheet based on data exist on data table module field

I use open XML library

Data table data as below :

Divide Output Excel File To Multi Tab based On Module
PartId Company Files Tab Module
1222 micro Abc source 1
1321 silicon Abc source 1
1444 cd2 Abc types 2
1321 cd3 Abc types 2
1541 tvs Abc types 2


Expected Result :

Expected Result :

Create File ABC.xlsx with two sheet first sheet name source and second sheet name types based on module and load data related to every sheet based on data related to every sheet .

so if i have two modules meaning I have two sheet .

What I have tried:

public Boolean createExcelFile(DataTable Table,String FullFilePathName)
{
Boolean IsDone = false;
try
{
FileInfo CreatedFile = new FileInfo(FullFilePathName);
Boolean ISNew = false;
if (!CreatedFile.Exists)
{

ISNew = true;
}
using (var pck = new ExcelPackage(CreatedFile))
{
ExcelWorksheet ws;
if (ISNew == true)
{
ws = pck.Workbook.Worksheets.Add("Sheet");


if (System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.IsRightToLeft) // Right to Left for Arabic lang
{
ExcelWorksheetView wv = ws.View;
wv.ZoomScale = 100;
wv.RightToLeft = true;
ws.PrinterSettings.Orientation = eOrientation.Landscape;

}
else
{
ExcelWorksheetView wv = ws.View;
wv.ZoomScale = 100;
wv.RightToLeft = false;
ws.PrinterSettings.Orientation = eOrientation.Landscape;

}
ws.Cells.AutoFitColumns();
ws.Cells[1, 1].LoadFromDataTable(Table, ISNew, OfficeOpenXml.Table.TableStyles.Light8);
}

else
{
ws = pck.Workbook.Worksheets.FirstOrDefault();
ws.Cells[2, 1].LoadFromDataTable(Table, ISNew);
}
pck.Save();
IsDone = true;

}
}
catch (Exception ex)
{

throw ex;
}
return IsDone;
}

but problem code above create one files with one sheet only
so How to create files with multi sheet based on module ?
 
[CODE=csharp] PUT YOUR CODE HERE WHEN POSTING [/CODE] Its not rocket science and it helps us to read your code in the proper structured, indented and formatted way.

This is the last time I will ask you to post your code within the code tags provided. We have asked you time again to post your code in code tags. Here is one occasion I can point back to.

I refuse to babysit you, because you are to lazy or to inept to follow simple instructions. Until you learn to post your code in code tags which are provided by the forum editor, you will find your topics will be closed in future, just like this one.
 
Status
Not open for further replies.
Back
Top Bottom