C# 如何读取excel(.xlsm)文件,该文件通过C使用finansu加载项#
我有一个excel(.xlsm)文件,通过excel加载项“finansu”更新股票市场实时数据。 当我试图通过C#应用程序在“股票名称”列中读取excel数据时,它会显示正确的股票名称,但在“值”列中它不会显示任何内容。该“股票价值”列通过finansu加载项更新为实时值 请帮助我阅读这些值。 提前谢谢 以下是源代码:C# 如何读取excel(.xlsm)文件,该文件通过C使用finansu加载项#,c#,.net,excel,C#,.net,Excel,我有一个excel(.xlsm)文件,通过excel加载项“finansu”更新股票市场实时数据。 当我试图通过C#应用程序在“股票名称”列中读取excel数据时,它会显示正确的股票名称,但在“值”列中它不会显示任何内容。该“股票价值”列通过finansu加载项更新为实时值 请帮助我阅读这些值。 提前谢谢 以下是源代码: connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\";";
query = "SELECT * FROM [RealTime$]";
conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
conn.Open();
cmd = new OleDbCommand(query, conn);
da = new OleDbDataAdapter(cmd);
dt = new System.Data.DataTable();
da.Fill(dt);
OLEDB将无法检索您想要的数据。我不熟悉finansu加载项,但Excel Interop应该能够获得您需要的内容 示例代码:
using Microsoft.Office.Interop.Excel;
using System;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
var filename = @"C:\temp\Book1.xlsx";
var excel = new Microsoft.Office.Interop.Excel.Application();
var wb = excel.Workbooks.Open(filename);
Worksheet realtime = wb.Sheets["RealTime"];
foreach (Range row in realtime.UsedRange.Rows)
{
Console.WriteLine("{0}", row.Cells[1, 1].Value); // Column A
Console.WriteLine("{0}", row.Cells[1, 2].Value); // Column B
// etc ...
}
wb.Close(SaveChanges: false);
}
}
}
请把你目前掌握的密码贴出来。