在Microsoft.Office.Interop.Excel(控制台应用程序)c#中编码希伯来文本时遇到问题

时间:2016-08-24 08:44:00

标签: c# excel

我正在尝试使用Microsoft.Office.Interop.Excel创建一个新的excel文件,无论我在做什么,我正在使用xlsx文件填充乱码... 更多信息: 我从文本文件中填充数据表 然后使用数据表填充execl表

OfficeExcel.Worksheet excelWorkSheet = excelWorkBook.Sheets.Add();
                excelWorkSheet.Name = "789";
            for (int i = 1; i < table.Columns.Count + 1; i++)
            {
                excelWorkSheet.Cells[1, i] = table.Columns[i - 1].ColumnName;
            }

            for (int j = 0; j < table.Rows.Count; j++)
            {
                for (int k = 0; k < table.Columns.Count; k++)
                {
                    Encoding hebrewEncoding = Encoding.GetEncoding("windows-1255");
                    byte[] latinBytes = Encoding.GetEncoding("windows-1255").GetBytes(table.Rows[j].ItemArray[k].ToString());
                    excelWorkSheet.Cells[j + 2, k + 1] = hebrewEncoding.GetString(latinBytes);
                }
            }
        }
        excelWorkBook.SaveAs(path + ExcelfileName + ".xlsx", OfficeExcel.XlFileFormat.xlOpenXMLWorkbook,
                             misValue, misValue, misValue, misValue, OfficeExcel.XlSaveAsAccessMode.xlExclusive,
                             misValue, misValue, misValue, misValue, misValue);
        excelWorkBook.Close(true, misValue, misValue);
        excelApp.Quit();  

我已经尝试了各种类型的编码,显然我做错了什么。

here is what I'm getting

0 个答案:

没有答案
相关问题