Example #1
0
        public string[,] OpenExcel(string filename)
        {
            using (ClosedXML.Excel.XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook(filename))
            {
                ClosedXML.Excel.IXLWorksheet worksheet = workbook.Worksheet(1);
                int rc = worksheet.RangeUsed().RowCount();
                int cc = worksheet.RangeUsed().Row(1).CellCount();
                string[,] buff = new string[rc, cc];
                for (int i = 0; i < rc; i++)
                {
                    ClosedXML.Excel.IXLRow row = worksheet.Row(i + 1);
                    for (int j = 0; j < cc; j++)
                    {
                        ClosedXML.Excel.IXLCell cell = row.Cell(j + 1);
                        string value = cell.GetValue <string>();
                        buff[i, j] = value;
                    }
                }

                return(buff);
            }
        }