में डेटाटेबल से एक्सेल फ़ाइल से निर्यात करने के लिए कैसे करें मेरे पास एक डाटाटेबल है और इसे एक्सेल फ़ाइल में निर्यात करना चाहते हैं, यह एक डब्ल्यूपीएफ एप्लीकेशन है और मुझे जो समाधान मिले हैं वे वेब एप्लिकेशन एएसपीनेट के लिए हैं कृपया मदद करें ...wpf C#
Q
wpf C#
6
A
उत्तर
8
बस, यह बेहतर दृश्यमान बनाने के लिए सभी
Microsoft.Office.Interop.Excel.Application excel = null;
Microsoft.Office.Interop.Excel.Workbook wb = null;
object missing = Type.Missing;
Microsoft.Office.Interop.Excel.Worksheet ws = null;
Microsoft.Office.Interop.Excel.Range rng = null;
try
{
excel = new Microsoft.Office.Interop.Excel.Application();
wb = excel.Workbooks.Add();
ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.ActiveSheet;
for (int Idx = 0; Idx < dt.Columns.Count; Idx++)
{
ws.Range["A1"].Offset[0, Idx].Value = dt.Columns[Idx].ColumnName;
}
for (int Idx = 0; Idx < dt.Rows.Count; Idx++)
{ // <small>hey! I did not invent this line of code,
// I found it somewhere on CodeProject.</small>
// <small>It works to add the whole row at once, pretty cool huh?</small>
ws.Range["A2"].Offset[Idx].Resize[1, dt.Columns.Count].Value =
dt.Rows[Idx].ItemArray;
}
excel.Visible = true;
wb.Activate();
}
catch (COMException ex)
{
MessageBox.Show("Error accessing Excel: " + ex.ToString());
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
4
आप अपने डेटाटेबल से एक .csv (कॉमा सेपरेटेड वैल्यू फ़ाइल) सहेज सकते हैं। यह फ़ाइल एक्सेल में खोला जा सकता है।
इसके अलावा: चाहे यह डब्ल्यूपीएफ या विनफॉर्म है, कनवर्ट करना दोनों में समान है क्योंकि इसका रूपांतरण कोड आपकी भाषा में लिखा गया है यानी सी # और WPF या Winforms के लिए विशिष्ट नहीं है।
2
के लिए मुझे ठीक मेहनत के लिए धन्यवाद ... vb.net जैसे कुछ एक?
Dim excel As Microsoft.Office.Interop.Excel.Application = Nothing
Dim wb As Microsoft.Office.Interop.Excel.Workbook = Nothing
Dim missing As Object = Type.Missing
Dim ws As Microsoft.Office.Interop.Excel.Worksheet = Nothing
Dim rng As Microsoft.Office.Interop.Excel.Range = Nothing
उप ExcelFile (DataTable के रूप में डीटी ByVal)
Try
excel = New Microsoft.Office.Interop.Excel.Application()
wb = excel.Workbooks.Add()
ws = DirectCast(wb.ActiveSheet, Microsoft.Office.Interop.Excel.Worksheet)
For Idx As Integer = 0 To dt.Columns.Count - 1
ws.Range("A1").Offset(0, Idx).Value = dt.Columns(Idx).ColumnName
Next
For Idx As Integer = 0 To dt.Rows.Count - 1
' <small>hey! I did not invent this line of code,
' I found it somewhere on CodeProject.</small>
' <small>It works to add the whole row at once, pretty cool huh?</small>
' YES IT'S COOL Brother ...
ws.Range("A2").Offset(Idx).Resize(1, dt.Columns.Count).Value = dt.Rows(Idx).ItemArray
Next
excel.Visible = True
wb.Activate()
Catch ex As Exception
MessageBox.Show("Error accessing Excel: " & ex.ToString())
End Try
End Sub
1
एक ही रास्ता
ArrayList arr = (ArrayList)dataGridView.DataSource;
dt = ArrayListToDataTable(arr);
dataTable2Excel(dt, dataGridView, pFullPath_toExport, nameSheet);
http://www.codeproject.com/Articles/30169/Excel-export-from-DatagridView
http://support.microsoft.com/default.aspx?scid=kb;en-us;317719
संबंधित मुद्दे
- 1. WPF/C#
- 2. wpf C#
- 3. WPF/C# - सूची दृश्य
- 4. Listbox.ItemTemplate (WPF C#)
- 5. .NET/C#/WPF प्रोजेक्ट्स
- 6. रिबन विंडो में स्टेटस बार कैसे दिखाएं wpf C#
- 7. WPF डेटा ग्रिड, कॉपी के बाद Ctrl + C क्लिपबोर्ड, OnCopyingRowClipboardContent
- 8. कॉम्बोबॉक्स चयनित वैल्यू या चयनित इटैम बाध्यकारी WPF C#
- 9. प्रोग्रामेटिक रूप से एक WPF/C# Windows.Control.ToolTip कैसे दिखाएं?
- 10. C/C++
- 11. WPF
- 12. wpf
- 13. WPF
- 14. उत्पन्न और C/C++
- 15. C/C++ कोड
- 16. लंबे C/C++
- 17. C/C++ Preprocessing त्रुटि
- 18. wpf
- 19. अक्षम घटना बुदबुदाती C#
- 20. C++
- 21. .. C++
- 22. C++
- 23. C++
- 24. /C++
- 25. C++
- 26. C++
- 27. C#
- 28. % c
- 29. C.
- 30. C++
धन्यवाद! महान उदाहरण :) – asuciu