Экспорт текстов, введенных в текстовые поля в ASP.NET HTML-таблица в excel через microsoft.office.interop.excel (или любое другое предложение)
There is a table on the website and users enter data in the cells of the table. I edited the ready codes to pull the data entered by each user to different pages as follows. But the problem is: there are a lot of(2000) cells and I have to match them one by one in the code. I think this should be an easier way. I am waiting for your suggestions to me. (Sql will not be used) Thank you.
Что я уже пробовал:
<pre><td class="auto-style6">%<asp:TextBox ID="txtC7" runat="server" Width="28px"></asp:TextBox> </td> <td class="auto-style7">%<asp:TextBox ID="txtD7" runat="server" Width="28px"></asp:TextBox></td> </tr> <tr> <td class="auto-style5">(%)</td> <td class="auto-style6">%<asp:TextBox ID="txtC8" runat="server" Width="28px"></asp:TextBox></td> <td class="auto-style7">%<asp:TextBox ID="txtD8" runat="server" Width="28px"></asp:TextBox></td> </tr>
<pre>private static Microsoft.Office.Interop.Excel.Workbook mWorkBook; private static Microsoft.Office.Interop.Excel.Sheets mWorkSheets; private static Microsoft.Office.Interop.Excel.Application oXL; object mv= System.Reflection.Missing.Value; protected void Button1_Click(object sender, EventArgs e) { oXL = new Microsoft.Office.Interop.Excel.Application(); oXL.Visible = true; oXL.DisplayAlerts = false; string path = "D:\\output.xls"; if (!File.Exists(path)) { mWorkBook = oXL.Workbooks.Add(); } else { mWorkBook = oXL.Workbooks.Open(path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); } mWorkSheets = mWorkBook.Worksheets; Microsoft.Office.Interop.Excel.Worksheet mWSheet = (Worksheet)mWorkBook.Worksheets.Add(mv, mv, mv, mv); mWSheet.Name = DateTime.UtcNow.ToString().Replace(":", "-"); //Replace(":", String.Empty); mWSheet.Range["B8"].Value = "(%)"; mWSheet.Range["C7"].Value = "%" + txtC7.Text; mWSheet.Range["C8"].Value = "%" + txtC8.Text; mWSheet.Range["D7"].Value = "%" + txtD7.Text; mWSheet.Range["D8"].Value = "%" + txtD8.Text; mWorkBook.SaveAs(path, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, mv, mv, mv, mv, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, mv, mv, mv, mv, mv); mWorkBook.Close(mv, mv, mv); mWSheet = null; mWorkBook = null; oXL.Quit(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); }