san*_*sid 16 model-view-controller epplus
有人能指出我如何阅读Excel spreasheet的正确方向,使用EPPlus和MVC循环遍历所有行和列以检索值吗?所以我看到了创建spreasheet的例子,但没有找到任何关于打开excel文件并从中读取值的信息.任何帮助,将不胜感激.
TIA Sue ..
wei*_*mat 19
简单的例子
// Get the file we are going to process
var existingFile = new FileInfo(filePath);
// Open and read the XlSX file.
using (var package = new ExcelPackage(existingFile))
{
// Get the work book in the file
var workBook = package.Workbook;
if (workBook != null)
{
if (workBook.Worksheets.Count > 0)
{
// Get the first worksheet
var currentWorksheet = workBook.Worksheets.First();
// read some data
object col1Header = currentWorksheet.Cells[1, 1].Value;
Run Code Online (Sandbox Code Playgroud)
一个简单的示例,说明如何在 .net 4.5 中使用 EPPlus 读取 excel 文件
public void readXLS(string FilePath)
{
FileInfo existingFile = new FileInfo(FilePath);
using (ExcelPackage package = new ExcelPackage(existingFile))
{
//get the first worksheet in the workbook
ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
int colCount = worksheet.Dimension.End.Column; //get Column Count
int rowCount = worksheet.Dimension.End.Row; //get row count
for (int row = 1; row <= rowCount; row++)
{
for (int col = 1; col <= colCount; col++)
{
Console.WriteLine(" Row:" + row + " column:" + col + " Value:" + worksheet.Cells[row, col].Value.ToString().Trim());
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14867 次 |
| 最近记录: |