本文整理汇总了C#中NPOI.GetSheet方法的典型用法代码示例。如果您正苦于以下问题:C# NPOI.GetSheet方法的具体用法?C# NPOI.GetSheet怎么用?C# NPOI.GetSheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPOI
的用法示例。
在下文中一共展示了NPOI.GetSheet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Relatorio_PreencherDados
private void Relatorio_PreencherDados(NPOI.HSSF.UserModel.HSSFWorkbook xlPackage, System.Data.DataTable dados, String nomePlanilha, Boolean gerarCabecalho, Int32 primeiraLinha)
{
#region Declaração de variáveis
NPOI.SS.UserModel.ISheet worksheet = null;
Int32 colunasQtd = 0;
Int32 linhasQtd = 0;
Int32 registrosQtd = 0;
List<Int32> colunasDate = null;
List<Int32> colunasVarcharMax = null;
#endregion
try
{
#region Inicialização de objetos
if (xlPackage.GetSheet(nomePlanilha) != null)
{
worksheet = xlPackage.GetSheet(nomePlanilha);
}
else
{
worksheet = xlPackage.CreateSheet(nomePlanilha);
}
#endregion
#region Preenche os dados do relatório
colunasQtd = dados.Columns.Count;
linhasQtd = dados.Rows.Count;
#region CABEÇALHO
if (gerarCabecalho)
{
for (Int32 i = 0; i <= colunasQtd - 1; i++)
{
String nomeColuna = String.Empty;
nomeColuna = dados.Columns[i].Caption;
NPOI.SS.UserModel.IRow row = worksheet.GetRow(2);
if (row == null) row = worksheet.CreateRow(2);
NPOI.SS.UserModel.ICell cell = row.GetCell(i);
if (cell == null) cell = row.CreateCell(i);
cell.SetCellValue(nomeColuna);
}
}
#endregion
#region DADOS
colunasDate = new List<Int32>();
colunasVarcharMax = new List<Int32>();
registrosQtd = 1;
Int32 rowIndex = 0;
for (Int32 nRow = primeiraLinha; registrosQtd <= linhasQtd; nRow++)
{
for (Int32 nCol = 0; nCol < colunasQtd; nCol++)
{
NPOI.SS.UserModel.IRow row = worksheet.GetRow(nRow);
if (row == null) row = worksheet.CreateRow(nRow);
NPOI.SS.UserModel.ICell cell = row.GetCell(nCol);
if (cell == null) cell = row.CreateCell(nCol);
String valor = dados.Rows[rowIndex][nCol].ToString().Replace("'", "´");
if (dados.Columns[nCol].DataType.ToString() == "System.Decimal")
{
if (valor.Trim() != String.Empty)
{
cell.SetCellValue(Double.Parse(valor));
}
}
else if (dados.Columns[nCol].DataType.ToString() == "System.Int32")
{
if (valor.Trim() != String.Empty)
{
cell.SetCellValue(Int32.Parse(valor));
}
}
else
{
cell.SetCellValue(valor);
}
}
registrosQtd++;
rowIndex++;
}
#endregion
#endregion
}
catch (Exception ex)
//.........这里部分代码省略.........
示例2: RelatorioGerencial_PreencherDados
private void RelatorioGerencial_PreencherDados(NPOI.HSSF.UserModel.HSSFWorkbook xlPackage, System.Data.DataTable dados, String nomePlanilha)
{
#region Declaração de variáveis
NPOI.SS.UserModel.ISheet worksheet = null;
Int32 colunasQtd = 0;
Int32 linhasQtd = 0;
List<Int32> colunasDate = null;
List<Int32> colunasVarcharMax = null;
#endregion
try
{
#region Inicialização de objetos
if (xlPackage.GetSheet(nomePlanilha) != null)
{
worksheet = xlPackage.GetSheet(nomePlanilha);
}
else
{
worksheet = xlPackage.CreateSheet(nomePlanilha);
}
#endregion
#region Preenche os dados do relatório
colunasQtd = dados.Columns.Count;
linhasQtd = dados.Rows.Count;
#region CABEÇALHO
for (Int32 i = 0; i <= colunasQtd - 1; i++)
{
String nomeColuna = String.Empty;
nomeColuna = dados.Columns[i].Caption;
NPOI.SS.UserModel.IRow row = worksheet.GetRow(2);
if (row == null) row = worksheet.CreateRow(2);
NPOI.SS.UserModel.ICell cell = row.GetCell(i);
if (cell == null) cell = row.CreateCell(i);
cell.SetCellValue(nomeColuna);
}
#endregion
#region DADOS
colunasDate = new List<Int32>();
colunasVarcharMax = new List<Int32>();
for (Int32 nRow = 2; nRow <= (linhasQtd + 1); nRow++)
{
for (Int32 nCol = 0; nCol <= colunasQtd - 1; nCol++)
{
NPOI.SS.UserModel.IRow row = worksheet.GetRow(nRow + 1);
if (row == null) row = worksheet.CreateRow(nRow + 1);
NPOI.SS.UserModel.ICell cell = row.GetCell(nCol);
if (cell == null) cell = row.CreateCell(nCol);
String valor = dados.Rows[nRow - 2][nCol].ToString().Replace("'", "´");
if (dados.Columns[nCol].DataType.ToString() == "System.Decimal")
{
if (valor.Trim() != String.Empty)
{
cell.SetCellValue(Double.Parse(valor));
}
}
else if (dados.Columns[nCol].DataType.ToString() == "System.Int32")
{
if (valor.Trim() != String.Empty)
{
cell.SetCellValue(Int32.Parse(valor));
}
}
else
{
cell.SetCellValue(valor);
}
}
}
#endregion
#endregion
}
catch (Exception ex)
{
#region Tratamento de erro
throw new Exception("MMAA.Pedidos.Web.WS.Pedido.Relatorio_PreencherDados: " + ex.Message);
#endregion
}
}