最近做NPOI导出EXCEL,之前给边框加粗线。 for (int i = 0; i <= 1; i++)
{
for(int j = 0; j <= 2; j++)
{
s.GetRow(i).GetCell(j).CellStyle = style;
}
}结果报错了,引发的异常:“System.NullReferenceException”我就单独做一个,for (int i = 0; i <= 2; i++)
{
for (int j = 0; j <= 5; j++)
{
Console.Write("{i}:{j}", i , j);
}
Console.WriteLine();
}结果还是报错,
“System.FormatException”类型的未经处理的异常在 mscorlib.dll 中发生 其他信息: 输入字符串的格式不正确。
不知怎么写才正确,指教一下,谢谢。
{
for(int j = 0; j <= 2; j++)
{
s.GetRow(i).GetCell(j).CellStyle = style;
}
}结果报错了,引发的异常:“System.NullReferenceException”我就单独做一个,for (int i = 0; i <= 2; i++)
{
for (int j = 0; j <= 5; j++)
{
Console.Write("{i}:{j}", i , j);
}
Console.WriteLine();
}结果还是报错,
“System.FormatException”类型的未经处理的异常在 mscorlib.dll 中发生 其他信息: 输入字符串的格式不正确。
不知怎么写才正确,指教一下,谢谢。
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
for (int i = 0; i <= 2; i++)
{
for (int j = 0; j <= 5; j++)
{
Console.Write("i是{0},j是{1}", i, j);
Console.Write("\n "); }
Console.WriteLine(); }
Console.ReadLine(); }
catch (Exception ex)
{
throw;
}
}
}
}
https://www.cnblogs.com/luowende2012/archive/2012/07/28/2612848.html
{
Form1 f = new Form1(); ISheet s = w.CreateSheet("a");
w.CreateSheet("b");
w.CreateSheet("c"); IRow r= s.CreateRow(1); ICell cell= r.CreateCell(1);
ICellStyle style = w.CreateCellStyle();
style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thick;
style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; ICellStyle cel = gets(); s.CreateRow(0).CreateCell(0).SetCellValue("测试1");
s.GetRow(0).CreateCell(1).SetCellValue("测试2");
s.GetRow(0).CreateCell(2).SetCellValue(textBox2.Text);
s.CreateRow(1).CreateCell(0).SetCellValue("测试222");
s.CreateRow(1).CreateCell(1).SetCellValue(Convert.ToDouble(textBox1.Text));
s.GetRow(1).CreateCell(2).SetCellValue(Convert.ToDouble(textBox2.Text));
for (int i = 0; i <= 1; i++)
{
for(int j = 0; j <= 2; j++)
{
s.GetRow(i).GetCell(j).CellStyle = style;
}
}
s.CreateRow(2).CreateCell(1).SetCellValue(f.textBox1.Text);
s.GetRow(2).CreateCell(2).SetCellValue(f.textBox2.Text);
s.GetRow(2).CreateCell(3).SetCellValue(label5.Text);
FileStream file = new FileStream(@"test.xls", FileMode.Create); w.Write(file); file.Close();
}