xls 파일의 셀에서 DateTime을 읽어야하지만 내용을 날짜 또는 문자열로 반환하는 대신 셀 내용이 유효하지 않습니다. 이는 숫자를 반환합니다.ExcelLibrary를 .NET에서 사용할 때 유효하지 않은 데이터
using System.IO;
using ExcelLibrary.SpreadSheet;
namespace XLSX_reader
{
class Program
{
private static ExcelDocument XlsDocument { get; set; }
static void Main(string[] args)
{
var inputStream = new MemoryStream(File.ReadAllBytes("d:\\Work\\Flexportal_Other\\Importers\\11-2016_Uitzendrapportage_SRS_Personeel_85873112442611460665848.xls"));
XlsDocument = new ExcelDocument(inputStream, null);
Cell cell1 = XlsDocument.GetCell(6, 4);
XlsDocument.GetCell(5, 7);
var date = ExcelDocument.ParseDateTime(cell1);
}
}
}
ExcellDocument 클래스 : 코드는 파일을 읽을 수있는 XLS는 다음과 같습니다
namespace XLSX_reader
{
public class ExcelDocument
{
public ExcelDocument(MemoryStream stream, string sheetName = null)
{
Workbook = LoadWorkbook(stream);
if (Workbook == null)
{
throw new InvalidOperationException("err");
}
Worksheet = LoadWorksheet(sheetName);
}
public Worksheet LoadWorksheet(string sheetName = null)
{
if (Workbook == null)
{
throw new InvalidOperationException(
"##(Load workbook before loading worksheets)(Open eerst een werkboek alvorens een werkblad te openen)##");
}
Worksheet = sheetName != null
? Workbook.Worksheets.FirstOrDefault(ws => ws.SheetType == SheetType.Worksheet && ws.Name == sheetName)
: Workbook.Worksheets.FirstOrDefault(ws => ws.SheetType == SheetType.Worksheet);
if (Worksheet == null)
{
throw new InvalidOperationException("##noWorksheetLoaded##");
}
RowIndexMin = Worksheet.Cells.FirstRowIndex;
RowIndexMax = Worksheet.Cells.LastRowIndex;
_rowIndex = RowIndexMin - 1;
return Worksheet;
}
public Cell GetCell(int row, int column)
{
return Worksheet.Cells[row, column];
}
}
}
결과는 날짜가 아닌 42443입니다. 왜 이런 일이 발생하고 어떻게 해결할 수 있습니까? 감사
이 참조 날짜 와 시간을 나타냅니다. htm 변환 방법은 다음과 같습니다. http://stackoverflow.com/questions/727466/how-do-i-convert-an-excel-serial-date-number-to-a-net-datetime – PaulF