我尝试读取RTF文件并将其发送到Excel文件。我这样做:
Byte[] rtf;
using (FileStream stream = new FileStream(Server.MapPath("/1.RTF"),
FileMode.Open, FileAccess.Read))
{
int size = Convert.ToInt32(stream.Length);
rtf = new Byte[size];
stream.Read(rtf, 0, size);
};
textx = System.Text.Encoding.GetEncoding("utf-8").GetString(rtf);
string file = @"C:\Users\ITS_prog\Desktop\newdoc.xls";
Workbook workbook = Workbook.Load(file);
Worksheet worksheet = workbook.Worksheets[1];
worksheet.Cells[0, 1] = new Cell((short)1);
worksheet.Cells[2, 0] = new Cell(9999999);
worksheet.Cells[3, 3] = new Cell((decimal)3.45);
worksheet.Cells[2, 2] = new Cell(textx);
worksheet.Cells[2, 4] = new Cell("Second string");
worksheet.Cells[4, 0] = new Cell(32764.5, "#,##0.00");
worksheet.Cells[5, 1] = new Cell(DateTime.Now, @"YYYY-MM-DD");
worksheet.Cells.ColumnWidth[0, 1] = 3000;
workbook.Save(file);
但在这一行中,Workbook workbook = Workbook.Load(file);
我的应用提供例外:
异常无法读取超出流的结尾。
我做错了什么?