PDA

View Full Version : Error BADRESPONSE: Unexpected token ILLEGAL



aydada
Aug 07, 2014, 4:50 AM
Hi all. I newbie ext.net
i ext.net shaving trying to use NPOI to output combined with excel formatted according to the template execution flow following message;
BADRESPONSE: Unexpected token ILLEGAL
Here is my code


protected void btnXuatExcelNhieu_Click(object sender, DirectEventArgs e)
{
DataTable dt = new DataTable();
daDuLieuNguon dDuLieu = new daDuLieuNguon();
try { dDuLieu.DuLieuNguon.IDTrangThai = int.Parse(slbTrangThai.SelectedItem.Value); }
catch { dDuLieu.DuLieuNguon.IDLanNhap = 0; }
DateTime tungay = Convert.ToDateTime(FieldNgayNhapTu.Text);
DateTime denngay = Convert.ToDateTime(FieldNgayNhapDen.Text);
dt = dDuLieu.DanhSach_TheoTrangThai(tungay, denngay);

FileStream fs = new FileStream(Server.MapPath(@"\template\BaoCaoSoLieu.xls"), FileMode.Open, FileAccess.Read);
HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs, true);
HSSFSheet sheet = templateWorkbook.GetSheet("Sheet1");

int max = dt.Rows.Count;
int i = 1;
if (max > 0)
{
foreach (DataRow dr in dt.Rows)
{
HSSFRow row = sheet.CreateRow(i);
row.CreateCell(0).SetCellValue(dr["SoHieu"].ToString());
row.CreateCell(1).SetCellValue(dr["TenTrangThai"].ToString());
row.CreateCell(2).SetCellValue(Convert.ToDateTime( dr["NgayPhat"].ToString()).ToString("dd/MM/yyy"));
row.CreateCell(3).SetCellValue(dr["PhuongThucGiaoHang"].ToString());
row.CreateCell(4).SetCellValue(dr["SoDonHang"].ToString());
row.CreateCell(5).SetCellValue(dr["TienCOD"].ToString());
row.CreateCell(6).SetCellValue(dr["MA"].ToString());
row.CreateCell(7).SetCellValue(dr["MaHang"].ToString());
row.CreateCell(8).SetCellValue(dr["TenHang"].ToString());
row.CreateCell(9).SetCellValue(dr["KM1"].ToString());
row.CreateCell(10).SetCellValue(dr["KM2"].ToString());
row.CreateCell(11).SetCellValue(dr["KM3"].ToString());
row.CreateCell(12).SetCellValue(dr["KM4"].ToString());
row.CreateCell(13).SetCellValue(dr["TenKHNhan"].ToString());
row.CreateCell(14).SetCellValue(dr["SDT1"].ToString());
row.CreateCell(15).SetCellValue(dr["SDT2"].ToString());
row.CreateCell(16).SetCellValue(dr["DiaChi"].ToString());
row.CreateCell(17).SetCellValue(dr["KhuVuc"].ToString());
row.CreateCell(18).SetCellValue(Convert.ToDateTime (dr["NgayKhachHangGiao"].ToString()).ToString("dd/MM/yyyy"));
row.CreateCell(19).SetCellValue(dr["TrongLuongTinhCuoc"].ToString());
row.CreateCell(20).SetCellValue(dr["CuocDV"].ToString());
row.CreateCell(21).SetCellValue(dr["CuocCOD"].ToString());
row.CreateCell(22).SetCellValue(dr["CuocKhac"].ToString());
row.CreateCell(23).SetCellValue(dr["DonViChapNhan"].ToString());
row.CreateCell(24).SetCellValue(dr["GhiChu"].ToString());
row.CreateCell(25).SetCellValue(dr["DienGiai"].ToString());
row.CreateCell(26).SetCellValue(dr["TrangThaiPaypost"].ToString());
i = i + 1;
}
}


sheet.ForceFormulaRecalculation = true;

MemoryStream ms = new MemoryStream();

templateWorkbook.Write(ms);
string fileName = "BaoCaoSoLieuTuNgay " + Convert.ToDateTime(FieldNgayNhapTu.Text).ToString("dd/MM/yyyy") + " DenNgay " + Convert.ToDateTime(FieldNgayNhapDen.Text).ToString ("dd/MM/yyyy") + ".xls";

HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", fileName));
response.Clear();

response.BinaryWrite(ms.GetBuffer());
response.End();

}


hope the support from everyone

Vladimir
Aug 07, 2014, 11:10 AM
Did you set IsUpload="true" for direct event?

aydada
Aug 07, 2014, 11:46 AM
thanks you verry much