<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem Load Data Excel with Microsoft.Office.Interop.Excel for .NET 4.8 in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/problem-load-data-excel-with-microsoft-office-interop-excel-for/m-p/12883020#M3436</link>
    <description>&lt;P&gt;dear friend, in the next code i have a problem with the word 'DataTable', is this beacause DataTable appear content in 'using System.Data;' and 'using Autodesk.AutoCAD.DatabaseServices;':&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;help&amp;nbsp; me please, the code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using Autodesk.AutoCAD.DatabaseServices;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.ComponentModel;&lt;BR /&gt;using System.Data;&lt;BR /&gt;using System.Drawing;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using System.Threading.Tasks;&lt;BR /&gt;using System.Windows.Forms;&lt;BR /&gt;// HOW TO IMPORT EXCEL FILE TO DATAGRIDVIEW AND SAVE TO DATABASE USING C#&lt;BR /&gt;// using Microsoft.Office.Interop.Excel;&lt;BR /&gt;// C# Tutorial - Open and Read Excel Files (*.xls/*.xlsx) | FoxLearn&lt;BR /&gt;using ExcelDataReader;&lt;BR /&gt;using System.IO;&lt;BR /&gt;//using System.Data;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;namespace DisanV01.Forms&lt;BR /&gt;//namespace DisanV01&lt;BR /&gt;{&lt;BR /&gt;public partial class UI_Inicio02_MetodoDeHunter : UserControl&lt;BR /&gt;{&lt;BR /&gt;public UI_Inicio02_MetodoDeHunter()&lt;BR /&gt;{&lt;BR /&gt;InitializeComponent();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void label1_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;private void cboSheet_SelectedIndexChanged(object sender, EventArgs e)&lt;BR /&gt;{&lt;BR /&gt;DataTable dt = tableCollection[cboSheet.SelectedItem.ToString()];&lt;BR /&gt;// dataGridView1.datasource&lt;BR /&gt;// dataGridView1.DataSource = dt;&lt;BR /&gt;dataGridView1.DataSource = dt;&lt;BR /&gt;}&lt;BR /&gt;private void button3_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;DataTableCollection tableCollection;&lt;/P&gt;&lt;P&gt;private void inicio_metododehunter_004_btnImport_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;BR /&gt;//HOW TO IMPORT EXCEL FILE TO DATAGRIDVIEW AND SAVE TO DATABASE USING C#&lt;BR /&gt;//Microsoft.Office.Interop.Excel.Application xlApp;&lt;BR /&gt;//Microsoft.Office.Interop.Excel.Workbook xlWorkbook;&lt;BR /&gt;//Microsoft.Office.Interop.Excel.Worksheet xlWorksheet;&lt;BR /&gt;//Microsoft.Office.Interop.Excel.Range xlRange;&lt;/P&gt;&lt;P&gt;//int xlRow;&lt;BR /&gt;//string strFileName;&lt;/P&gt;&lt;P&gt;//openFD.Filter = "Excel Office |*.xls; *.xlsx";&lt;BR /&gt;//openFD.ShowDialog();&lt;BR /&gt;//strFileName = openFD.FileName;&lt;/P&gt;&lt;P&gt;//if(strFileName != "")&lt;BR /&gt;//{&lt;BR /&gt;// xlApp = new Microsoft.Office.Interop.Excel.Application();&lt;BR /&gt;// xlWorkbook = xlApp.Workbooks.Open(strFileName);&lt;BR /&gt;// xlWorksheet = xlWorkbook.Worksheets["Hoja1"];&lt;BR /&gt;// xlRange = xlWorksheet.UsedRange;&lt;/P&gt;&lt;P&gt;// int i = 0;&lt;/P&gt;&lt;P&gt;// for (xlRow = 2; xlRow &amp;lt;= xlRange.Rows.Count; xlRow++)&lt;BR /&gt;// {&lt;BR /&gt;// i++;&lt;BR /&gt;// inicio_metododehunter_006.Rows.Add(i, xlRange.Cells[xlRow, 1].Text, xlRange.Cells[xlRow, 2].Text);&lt;BR /&gt;// }&lt;BR /&gt;// xlWorkbook.Close();&lt;BR /&gt;// xlApp.Quit();&lt;BR /&gt;//}&lt;/P&gt;&lt;P&gt;// C# Tutorial - Open and Read Excel Files (*.xls/*.xlsx) | FoxLearn&lt;BR /&gt;{&lt;BR /&gt;using(OpenFileDialog openFD=new OpenFileDialog() { Filter= "Excel 97-2003 Workbook|*.xls|Excel Workbook|*.xlsx" })&lt;BR /&gt;{&lt;BR /&gt;if (openFD.ShowDialog() == DialogResult.OK)&lt;BR /&gt;{&lt;BR /&gt;txtFilename.Text = openFD.FileName;&lt;BR /&gt;using(var stream=File.Open(openFD.FileName, FileMode.Open, FileAccess.Read))&lt;BR /&gt;{&lt;BR /&gt;using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))&lt;BR /&gt;{&lt;BR /&gt;DataSet result = reader.AsDataSet(new ExcelDataSetConfiguration()&lt;BR /&gt;{&lt;BR /&gt;ConfigureDataTable = (_) =&amp;gt; new ExcelDataTableConfiguration() { UseHeaderRow = true }&lt;BR /&gt;});&lt;BR /&gt;tableCollection = result.Tables;&lt;BR /&gt;cboSheet.Items.Clear();&lt;BR /&gt;foreach (DataTable table in tableCollection)&lt;BR /&gt;cboSheet.Items.Add(table.TableName);&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void checkBox1_CheckedChanged(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;private void label2_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;private void label3_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Sun, 07 Jul 2024 22:45:48 GMT</pubDate>
    <dc:creator>08130182</dc:creator>
    <dc:date>2024-07-07T22:45:48Z</dc:date>
    <item>
      <title>Problem Load Data Excel with Microsoft.Office.Interop.Excel for .NET 4.8</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-load-data-excel-with-microsoft-office-interop-excel-for/m-p/12869464#M3434</link>
      <description>&lt;P&gt;Hola a todos:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;En este día quiero ejecutar una parcela en AutoCAD 2024 a través de .NET (Biblioteca de clases - Framework 4.8), en la parcela un botón al hacer 'clic' debería abrir un 'filedialog' y cargar los datos de excel y renderizar en un DataGridView.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;En el caso de AutoCAD no funciona el clic&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="08130182_1-1719726644246.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1381553iCD35FACA56107816/image-size/medium?v=v2&amp;amp;px=400" role="button" title="08130182_1-1719726644246.png" alt="08130182_1-1719726644246.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Figura 01: Clic en 'Cargar archivo' y no funciona el botón.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A continuación, intento ejecutar un ejemplo mientras se ve un tutorial&lt;/P&gt;&lt;P&gt;(&lt;FONT&gt;&lt;A href="https://www.youtube.com/watch?v=LDq4C_wF0fs" target="_blank"&gt;https://www.youtube.com/watch?v=LDq4C_wF0fs&lt;/A&gt;) , pero aparece otro error, para este caso el problema es diferente, i cuando se crea una nueva configuración de solución como (Aplicación de Windows Forms - .NET Framework 4.8), pero no se pueden cargar los datos de Excel. Reviso una pregunta en stackOverFlow, pero cambio en la compilación para 32 bits y el problema continúa. Ayúdame por favor&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="08130182_0-1719726299851.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1381551i04A899263834CBD8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="08130182_0-1719726299851.png" alt="08130182_0-1719726299851.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Figura 02: Ejecución del código replicado del tutorial&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2024 05:57:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-load-data-excel-with-microsoft-office-interop-excel-for/m-p/12869464#M3434</guid>
      <dc:creator>08130182</dc:creator>
      <dc:date>2024-06-30T05:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problem Load Data Excel with Microsoft.Office.Interop.Excel for .NET 4.8</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-load-data-excel-with-microsoft-office-interop-excel-for/m-p/12869822#M3435</link>
      <description>&lt;P&gt;You should post your code (using the "&amp;lt;/&amp;gt;" button above the message window), instead of showing a picture with only partial code barely readable).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have to actually make Excel running as separate application&amp;nbsp;in parallel along with AutoCAD in the workflow? Or, you actually ONLY need read data from the sheet(s) in a *.xlsx file? If it is the latter, automating Excel app via COM is a bad solution: the data in *xlsx file can be easily read (or even saved back) without having to make Excel app runs, or installed at all. There are many free/open source .NET libraries one can use to access data in *.xlsx file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one of the tutorial in youtube:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.youtube.com/watch?v=5U2qf52PTTY" target="_blank" rel="noopener"&gt;https://www.youtube.com/watch?v=5U2qf52PTTY&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jun 2024 13:46:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-load-data-excel-with-microsoft-office-interop-excel-for/m-p/12869822#M3435</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2024-06-30T13:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem Load Data Excel with Microsoft.Office.Interop.Excel for .NET 4.8</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-load-data-excel-with-microsoft-office-interop-excel-for/m-p/12883020#M3436</link>
      <description>&lt;P&gt;dear friend, in the next code i have a problem with the word 'DataTable', is this beacause DataTable appear content in 'using System.Data;' and 'using Autodesk.AutoCAD.DatabaseServices;':&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;help&amp;nbsp; me please, the code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using Autodesk.AutoCAD.DatabaseServices;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.ComponentModel;&lt;BR /&gt;using System.Data;&lt;BR /&gt;using System.Drawing;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using System.Threading.Tasks;&lt;BR /&gt;using System.Windows.Forms;&lt;BR /&gt;// HOW TO IMPORT EXCEL FILE TO DATAGRIDVIEW AND SAVE TO DATABASE USING C#&lt;BR /&gt;// using Microsoft.Office.Interop.Excel;&lt;BR /&gt;// C# Tutorial - Open and Read Excel Files (*.xls/*.xlsx) | FoxLearn&lt;BR /&gt;using ExcelDataReader;&lt;BR /&gt;using System.IO;&lt;BR /&gt;//using System.Data;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;namespace DisanV01.Forms&lt;BR /&gt;//namespace DisanV01&lt;BR /&gt;{&lt;BR /&gt;public partial class UI_Inicio02_MetodoDeHunter : UserControl&lt;BR /&gt;{&lt;BR /&gt;public UI_Inicio02_MetodoDeHunter()&lt;BR /&gt;{&lt;BR /&gt;InitializeComponent();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void label1_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;private void cboSheet_SelectedIndexChanged(object sender, EventArgs e)&lt;BR /&gt;{&lt;BR /&gt;DataTable dt = tableCollection[cboSheet.SelectedItem.ToString()];&lt;BR /&gt;// dataGridView1.datasource&lt;BR /&gt;// dataGridView1.DataSource = dt;&lt;BR /&gt;dataGridView1.DataSource = dt;&lt;BR /&gt;}&lt;BR /&gt;private void button3_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;DataTableCollection tableCollection;&lt;/P&gt;&lt;P&gt;private void inicio_metododehunter_004_btnImport_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;BR /&gt;//HOW TO IMPORT EXCEL FILE TO DATAGRIDVIEW AND SAVE TO DATABASE USING C#&lt;BR /&gt;//Microsoft.Office.Interop.Excel.Application xlApp;&lt;BR /&gt;//Microsoft.Office.Interop.Excel.Workbook xlWorkbook;&lt;BR /&gt;//Microsoft.Office.Interop.Excel.Worksheet xlWorksheet;&lt;BR /&gt;//Microsoft.Office.Interop.Excel.Range xlRange;&lt;/P&gt;&lt;P&gt;//int xlRow;&lt;BR /&gt;//string strFileName;&lt;/P&gt;&lt;P&gt;//openFD.Filter = "Excel Office |*.xls; *.xlsx";&lt;BR /&gt;//openFD.ShowDialog();&lt;BR /&gt;//strFileName = openFD.FileName;&lt;/P&gt;&lt;P&gt;//if(strFileName != "")&lt;BR /&gt;//{&lt;BR /&gt;// xlApp = new Microsoft.Office.Interop.Excel.Application();&lt;BR /&gt;// xlWorkbook = xlApp.Workbooks.Open(strFileName);&lt;BR /&gt;// xlWorksheet = xlWorkbook.Worksheets["Hoja1"];&lt;BR /&gt;// xlRange = xlWorksheet.UsedRange;&lt;/P&gt;&lt;P&gt;// int i = 0;&lt;/P&gt;&lt;P&gt;// for (xlRow = 2; xlRow &amp;lt;= xlRange.Rows.Count; xlRow++)&lt;BR /&gt;// {&lt;BR /&gt;// i++;&lt;BR /&gt;// inicio_metododehunter_006.Rows.Add(i, xlRange.Cells[xlRow, 1].Text, xlRange.Cells[xlRow, 2].Text);&lt;BR /&gt;// }&lt;BR /&gt;// xlWorkbook.Close();&lt;BR /&gt;// xlApp.Quit();&lt;BR /&gt;//}&lt;/P&gt;&lt;P&gt;// C# Tutorial - Open and Read Excel Files (*.xls/*.xlsx) | FoxLearn&lt;BR /&gt;{&lt;BR /&gt;using(OpenFileDialog openFD=new OpenFileDialog() { Filter= "Excel 97-2003 Workbook|*.xls|Excel Workbook|*.xlsx" })&lt;BR /&gt;{&lt;BR /&gt;if (openFD.ShowDialog() == DialogResult.OK)&lt;BR /&gt;{&lt;BR /&gt;txtFilename.Text = openFD.FileName;&lt;BR /&gt;using(var stream=File.Open(openFD.FileName, FileMode.Open, FileAccess.Read))&lt;BR /&gt;{&lt;BR /&gt;using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))&lt;BR /&gt;{&lt;BR /&gt;DataSet result = reader.AsDataSet(new ExcelDataSetConfiguration()&lt;BR /&gt;{&lt;BR /&gt;ConfigureDataTable = (_) =&amp;gt; new ExcelDataTableConfiguration() { UseHeaderRow = true }&lt;BR /&gt;});&lt;BR /&gt;tableCollection = result.Tables;&lt;BR /&gt;cboSheet.Items.Clear();&lt;BR /&gt;foreach (DataTable table in tableCollection)&lt;BR /&gt;cboSheet.Items.Add(table.TableName);&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void checkBox1_CheckedChanged(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;private void label2_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;private void label3_Click(object sender, EventArgs e)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jul 2024 22:45:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-load-data-excel-with-microsoft-office-interop-excel-for/m-p/12883020#M3436</guid>
      <dc:creator>08130182</dc:creator>
      <dc:date>2024-07-07T22:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problem Load Data Excel with Microsoft.Office.Interop.Excel for .NET 4.8</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-load-data-excel-with-microsoft-office-interop-excel-for/m-p/12883372#M3437</link>
      <description>&lt;P&gt;To avoid conflict between Autodesk.AutoCAD.DatabaseServices.DataTable and System.Data.DataTable, you can simply use the full name (as upper) or use a &lt;A href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive#using-alias" target="_blank" rel="noopener"&gt;using alias directive&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please, use the 'Insert/Edit code sample' button [&amp;lt;/&amp;gt;] when you paste code.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 06:15:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-load-data-excel-with-microsoft-office-interop-excel-for/m-p/12883372#M3437</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-07-08T06:15:46Z</dc:date>
    </item>
  </channel>
</rss>

