2012-05-29 52 views
1

我使用EPPlus 3.0(codeplex latest library)库下载excel文件。一切工作正常,但一些列显示与"_x00D_"数据字符串。我在谷歌研究,大家都说它是换行符。我尝试过所有场景仍然无法使用。_x00D_使用EPPlus库在Excel中显示?

请指教我。

Using pck As New ExcelPackage() 
        'Create the worksheets 
    Dim wsAll As ExcelWorksheet = pck.Workbook.Worksheets.Add("All") 
    Dim wsManufacturing As ExcelWorksheet = pck.Workbook.Worksheets.Add("Manufacturing") 
    Dim wsHealthcare As ExcelWorksheet = pck.Workbook.Worksheets.Add("Healthcare") 
    Dim wsManagement As ExcelWorksheet = pck.Workbook.Worksheets.Add("Management") 
    Dim wsSelling As ExcelWorksheet = pck.Workbook.Worksheets.Add("Selling") 

    'Load the datatable into the sheet, starting from cell A1. Print the column names on row 1 
    wsAll.Cells("A1").LoadFromDataTable(dtAllDownload, True) 
    If dtManufacturing.Rows.Count > 0 Then 
    wsManufacturing.Cells("A1").LoadFromDataTable(dtManufacturing, True) 
    End If 
    If dtChinaHealthcare.Rows.Count > 0 Then 
    wsHealthcare.Cells("A1").LoadFromDataTable(dtHealthcare, True) 
    End If 
    If dtChinaManagement.Rows.Count > 0 Then 
     wsManagement.Cells("A1").LoadFromDataTable(dtManagement, True) 
    End If 
    If dtSelling.Rows.Count > 0 Then 
     wsSelling.Cells("A1").LoadFromDataTable(dtSelling, True) 
    End If 

    Dim filename As String = "FullExtract_" & Now.Year.ToString & Now.Month.ToString & Now.Day.ToString & ".xlsx" 
    Dim fileBytes As [Byte]() = pck.GetAsByteArray() 
    HttpContext.Current.Response.Clear() 
    HttpContext.Current.Response.ClearContent() 
    HttpContext.Current.Response.ClearHeaders() 
    HttpContext.Current.Response.Cookies.Clear() 
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.[Private]) 
    HttpContext.Current.Response.CacheControl = "private" 
    HttpContext.Current.Response.Charset = System.Text.UTF8Encoding.UTF8.WebName 
    HttpContext.Current.Response.ContentEncoding = System.Text.UTF8Encoding.UTF8 
    HttpContext.Current.Response.AppendHeader("Content-Length", fileBytes.Length.ToString()) 
    HttpContext.Current.Response.AppendHeader("Pragma", "cache") 
    HttpContext.Current.Response.AppendHeader("Expires", "60") 
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" & filename) 
    HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" 
    HttpContext.Current.Response.BinaryWrite(fileBytes) 
    HttpContext.Current.Response.[End]() 
+0

你确定这个数据不从数据表来的? –

+0

不知道....... – James123

+0

那么,如果DataTable有这个,我会看起来第一件事 –

回答

0

我推断这个字符串从数据表来了,你可以用这个方法取代:

public static void Replace_x00D_(DataTable data) 
{ 
    List<DataColumn> stringColumns = new List<DataColumn>(); 
    foreach (DataColumn dc in data.Columns) 
    { 
    if (dc.DataType == typeof(string)) 
     stringColumns.Add(dc); 
    } 

    foreach (DataRow rw in data.Rows) 
    { 
    foreach (DataColumn dc in stringColumns) 
     rw.Field<string>(dc).Replace("_x00D_", ""); 
    } 
} 
+0

在数据表中搜索“x00D”字符串的所有字段。我在数据表中找不到任何东西。查看数据表中的空格 – James123

+0

生成此垃圾的列的类型是什么? –

+0

在nvarchar(200) – James123

相关问题