/ / निर्यात मूल्य कई शीट के साथ उत्कृष्टता के लिए - c #

एकाधिक चादरों के साथ एक्सेल करने के लिए मूल्य निर्यात करें - सी #

नीचे दिए गए कोड में मेरे पास एक्सेल लेखक है जब मैं मूल्यों का निर्यात करता हूं तो केवल एक शीट स्टोर करने के लिए उपलब्ध है मैं मूल्यों को स्टोर करने के लिए कई शीट चाहता हूं। मोती मुझे ऐसा करने में मदद करते हैं।

string SheetName="";//I am Getting values using Forloop i want to create each sheet.
using (Helper.ExcelWriter writer = new Helper.ExcelWriter(strFilePath))
{
writer.WriteStartDocument();
// Write the worksheet contents
writer.WriteStartWorksheet(SheetName);
//Write header row
writer.WriteStartRow();
//code
writer.WriteEndRow();
}

// Close up the document
writer.WriteEndWorksheet();
writer.WriteEndDocument();
writer.Close();

उत्तर:

उत्तर № 1 के लिए 1

यहाँ एक नमूना है, आप c # के साथ एक्सेल वर्कबुक में कई शीट कैसे जोड़ सकते हैं

पहले आपको आयात करना होगा Microsoft.Office.Interop.Excel संधर्भ से।

 Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
System.Windows.MessageBox.Show("Excel is not properly installed!!");
return;
}

Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;


//After creating the new Workbook, next step is to write content to worksheet

xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//Bind your columns and rows as you like in the worksheet. For example :
xlWorkSheet.Cells[1, 1] = "Column 1, Row 1 data ";

//Then re initiate the xlworksheet and do the same as before.
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);
xlWorkSheet.Cells[1, 1] = "Column 1, Row 1 data ";// 2nd sheet data

//Save the excel file after creating as much sheet you want.
xlWorkBook.SaveAs(path + "\" + exlFilename); // here the path/ location and the filename to be provided.