public void DailyOvertime(string fname)
{
var existingFile = new FileInfo(fname);
using (var package = new ExcelPackage(existingFile))
{
// Get the work book in the file
ExcelWorkbook workBook = package.Workbook;
if (workBook != null)
{
if (workBook.Worksheets.Count > 0)
{
// Get the first worksheet
ExcelWorksheet currentWorksheet = workBook.Worksheets.First();
// read some data
var Monday = currentWorksheet.GetValue(11, 4);
var Tuesday = currentWorksheet.GetValue(13, 4);
var Wednesday = currentWorksheet.GetValue(15, 4);
var Thursday = currentWorksheet.GetValue(17, 4);
var Friday = currentWorksheet.GetValue(19, 4);
var Saturday = currentWorksheet.GetValue(21, 4);
var Sunday = currentWorksheet.GetValue(23, 4);
}
}
}
}
运行此代码时出错。每次我到达ExcelWorkbook workBook = package.Workbook;
行时,程序都会中断,我无法弄清楚原因。我正在尝试打开一个.xlsx文件,到目前为止一切似乎都正常工作。
我注意到这条消息出现在当地人:
Workbook 'package.Workbook' threw an exception of type 'System.UriFormatException' OfficeOpenXml.ExcelWorkbook {System.UriFormatException}
任何帮助将不胜感激提前感谢!