I want to ask something I can't figure out how to fix it.
Please help me, so I need to develop an app meanwhile it's been ready to export to excel, but this app only can export the file one by one of the Tabs, so I need to join them manually, I need to know how to make it to be just 1 file and maybe can be 2 sheets excel file,
Thanks
private void DOCUMENT_GENERATOR(object sender, string DocPath)
{
try
{
foreach string DateTimeID = string.Format("{0:yyyyMMMdd}", DateTime.Now) + "_" + string.Format("{0:hhmmss}", DateTime.Now);
var resul = from c in Class.TreeMenusCls.items where c.ID.ToString() == treeView1.SelectedNode.Name select new { c.ID, c.MenuName, c.ParentID, c.Tag, c.CreateCtl, c.HeaderOnly };
foreach (var cat in resul)
{
var get_query = from s in QueryCollectionTable.Select() where Convert.ToInt16(s["KEY_MENUS"]) == MenuIDSelected orderby s["PRIORITY"] select s;
foreach (var Eq in get_query)
{
TabControl Tab;
Tab = (TabControl)this.Controls.Find("Tab" + Eq["KEY_MENUS"], true)[0];
Control.ControlCollection SearchCtl = Tab.TabPages[Convert.ToInt16(Eq["PRIORITY"])].Controls;
foreach (Control c in SearchCtl)
{
if (c.Name == "Grid" + Eq["NO_ID"])
{
Thread[] Tr = new Thread[0];
Array.Resize(ref Tr, Tr.Length + 1);
int priority = Convert.ToInt16(Eq["PRIORITY"]);
string query_name = Eq["QUERY_NAME"].ToString();
string menu_name = cat.MenuName;
int formated = Convert.ToInt16(Eq["FORMATED"]);
string row_start = Eq["ROW_START"].ToString();
string draft_location = Eq["DRAFT_LOCATION"].ToString();
string run_macro_name = Eq["RUN_MACRO_NAME"].ToString();
if (sender == EXCEL_CMD_GENERATE)
{
if (formated == 0)
Tr[Tr.Length - 1] = new Thread(new ThreadStart(delegate { this.Obj[0].ExcelGenerator((DataGridView)c, Tab, priority, query_name, menu_name, DateTimeID, DocPath); }));
else if (formated == 1)
Tr[Tr.Length - 1] = new Thread(new ThreadStart(delegate { this.Obj[0].ExcelFormated((DataGridView)c, Tab, priority, query_name, menu_name, DateTimeID, DocPath, formated, row_start, draft_location, run_macro_name); }));
}
if (sender == TEXT_CMD_GENERATE)
Tr[Tr.Length - 1] = new Thread(new ThreadStart(delegate { this.Obj[0].TextGenerator((DataGridView)c, Tab, priority, query_name, menu_name, DateTimeID, DocPath); }));
if (sender == CSV_CMD_GENERATE)
Tr[Tr.Length - 1] = new Thread(new ThreadStart(delegate { this.Obj[0].CsvGenerator((DataGridView)c, Tab, priority, query_name, menu_name, DateTimeID, DocPath); }));
if (sender == XML_CMD_GENERATE)
Tr[Tr.Length - 1] = new Thread(new ThreadStart(delegate { this.Obj[0].XmlGenerator((DataGridView)c, Tab, priority, query_name, menu_name, DateTimeID, DocPath); }));
Tr[Tr.Length - 1].Start();
}
}
}
}
}
catch (ArgumentNullException a)
{
Console.WriteLine(a.Message);
}
}
For export any data to excel, you can use ClosedXML.Report. It is a tool for report generation with which you can easily export any data from your .NET classes to Excel using a XLSX-template.
See more here https://github.com/ClosedXML/ClosedXML.Report
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.