J'utilise NPOI Excel Library pour générer un fichier Excel, dans ce fichier Excel je suis définir explicitement le type de colonne pour les colonnes telles que la date, chaîne, etc.NPOI ensemble explicite colonne Type ne fonctionne pas correctement
Im en utilisant la code suivant pour réaliser ceci.
var row = sheet.CreateRow(currentNPOIRowIndex++);
for (var colIndex = 0; colIndex < exportData.Columns.Count; colIndex++)
{
ICell cell = null;
cell = row.CreateCell(colIndex);
if (exportData.Columns[colIndex].DataType == typeof(DateTime))
{
if (exportData.Rows[rowIndex][colIndex].ToString() != "")
{
cell.SetCellValue((DateTime)exportData.Rows[rowIndex][colIndex]);
cell.CellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)book.CreateCellStyle();
cell.CellStyle.DataFormat = book.CreateDataFormat().GetFormat("yyyyMMdd HH:mm:ss");
cell = null;
}
else
cell.SetCellValue(exportData.Rows[rowIndex][colIndex].ToString());
}
else
cell.SetCellValue(exportData.Rows[rowIndex][colIndex].ToString());
}
}
Le code ci-dessus fonctionne bien pour 42 lignes à-dire qu'il correctement défini le type de colonne, mais après 42 lignes Type de colonne ne s'applique pas.
Toute aide sera grandement appréciée.
pouvez-vous essayer le dernier code. Je vous ai fourni ma solution réalisable. Merci. –