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文件,一切似乎都正常工作到這一點。EPPlus打開excel .xlsx文件錯誤
我沒有注意到這個消息是在當地人上來:
Workbook 'package.Workbook' threw an exception of type 'System.UriFormatException' OfficeOpenXml.ExcelWorkbook {System.UriFormatException}
任何幫助將提前不勝感激謝謝!
您是否檢查過使用調試器是否在該行中引發了任何異常?發佈例外以便縮小問題的範圍。 – LakshmiNarayanan
@LakshmiNarayanan:沒有任何東西被拋出,只是沒有提供任何信息就中斷了應用程序 – teepee
您是否在Excel中打開了XLSX文件?那總是發生在我身上...... –