protected DataTable SaveAsDataTable(Worksheet sheet) { uint minRow = sheet.Rows.MinRow + headRowCount; uint maxRow = sheet.Rows.MaxRow - endRowCount; //���ȷ������Ҫ������������� if (dataRowCount != 0) { maxRow = minRow + dataRowCount - 1; } Row firstRow = sheet.Rows[minRow]; uint minCol = firstRow.Cells.MinCol; uint maxCol = firstRow.Cells.MaxCol; if (dataColCount != 0) { maxCol = minCol + dataColCount - 1; } //for (uint i = minCol; i <= maxCol; i++) //{ // dt.Columns.Add(firstRow.Cells[i].FormattedValue()); //} string[] indexCol = indexDatatimeCol.Split(','); for (uint i = minRow; i <= maxRow; i++) { Row row = sheet.Rows[i]; if (row != null) { DataRow dr = dtExcel.NewRow(); if (row.Cells[0] == null) { continue; } bool isDate; for (uint j = minCol; j <= maxCol; j++) { Cell cell = row.Cells[j]; isDate = false; if (cell != null) { //�жϴ����Ƿ������ڸ�ʽ���� foreach (string col in indexCol) { if (string.IsNullOrEmpty(col)) { continue; } else { if (j == int.Parse(col)) { isDate = true; break; } } } if (isDate) { //������������ڸ�ʽ���ݣ�����ת���� dr[Convert.ToInt32(j)] = cell.Value != null ? ParseDateTime(cell.Value.ToString()).ToString("yyyy-MM-dd HH:mm") : string.Empty; } else { dr[Convert.ToInt32(j)] = cell.Value != null ? cell.Value.ToString().Trim('��').Trim('��').Trim('��') : string.Empty; } } } dtExcel.Rows.Add(dr); } } return dtExcel; }
protected DataTable SaveAsDataTable(Worksheet sheet) { DataTable dt = new DataTable(); uint minRow = sheet.Rows.MinRow; uint maxRow = sheet.Rows.MaxRow; Row firstRow = sheet.Rows[minRow]; uint minCol = firstRow.Cells.MinCol; uint maxCol = firstRow.Cells.MaxCol; for (uint i = minCol; i <= maxCol; i++) { dt.Columns.Add(firstRow.Cells[i].FormattedValue()); } for (uint i = minRow + 1; i <= maxRow; i++) { Row row = sheet.Rows[i]; if (row != null) { DataRow dr = dt.NewRow(); for (uint j = minCol; j <= maxCol; j++) { Cell cell = row.Cells[j]; if (cell != null) { dr[Convert.ToInt32(j)] = cell.Value != null ? cell.Value.ToString() : string.Empty; } } dt.Rows.Add(dr); } } return dt; }