简体   繁体   English

通过excel公式字符串读取Excel单元格值

[英]Reading Excel cell value by its excel formula string

My C#.Net application to load and read an excel sheet cell value by using an excel formula string .我的 C#.Net 应用程序使用 excel 公式字符串加载和读取 excel 工作表单元格值。

For example - The excel sheet location and the tab name along with its Cell row/column will be provided as a formula string.例如 - Excel 工作表位置和选项卡名称及其单元格行/列将作为公式字符串提供。

'D:\\DataX[Data.Xls]EOD'!$A5 'D:\\DataX[Data.Xls]EOD'!$A5

From the above formula - C# application to Load the Data.Xls from the location and open the EOD tabsheet and should read 5th row A column value.从上面的公式 - C# 应用程序从该位置加载 Data.Xls 并打开 EOD 标签页,应该读取第 5 行 A 列的值。

Looking for the best way to accomplish in C#.Net framework.寻找在 C#.Net 框架中完成的最佳方式。

                string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFileDialog1.FileName + ";Extended Properties='Excel 8.0;HDR=Yes;READONLY=true;IMEX=1;'";
                using (var connection = new System.Data.OleDb.OleDbConnection(con))
                {
                    connection.Open();

                    xlApp = new Application();
                    xlWorkbook = xlApp.Workbooks.Open(openFileDialog1.FileName);

                    for (int ipage = 1; ipage <= xlApp.ActiveWorkbook.Sheets.Count; ipage++)
                    {
                        Worksheet page = xlApp.ActiveWorkbook.Sheets[ipage];
                        page.Columns.ClearFormats();
                        sayfa.Rows.ClearFormats();
                        var xlRange = page.UsedRange;
                        var lastRow = page.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Row;
                        int sum = xlRange.Rows.Count - 1;

                        var columns = new List<string>();
                        string ObjecType = "";

                        for (int i = 1; i < xlRange.Columns.Count + 1; i++)
                        {
                        
                        }
                    
                    }
                    
                    connection.Close();
                }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM