nmd
12-10-2010, 16:01
Mình dùng C# để viết site asp.net. Trong đó, mình đọc file Excel up lên từ client.
private void ReadWriteExcelData(string strName)
{
string connectionString1 = @"Provider=Microsoft.Jet. OLEDB.4.0;Data Source=" + Server.MapPath(strName) + ";Extended Properties=Excel 8.0;";
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open(Server.MapPath(strName), 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindow s, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1) ;
range = xlWorkSheet.UsedRange;
string strDienthoai = "";
string strNoidung = "";
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
Excel.Range temp = (range.Cells[rCnt, cCnt] as Excel.Range);
if (temp.Value2 != null)
{
strDienthoai = temp.Value2.ToString();
}
Vấn đề là file Excel dùng font chữ VNI-Time. Mình đã cài đặt font để view file Excel đọc bình thường.
Nhưng khi đọc file bằng code thì thấy chữ không đọc được. Ví dụ đáng lẽ Nguyễn Văn A thì nó hiển thị chữ lung tung do không đúng font.
Xin hỏi mình phải làm sao để khắc phục vấn đề này?
private void ReadWriteExcelData(string strName)
{
string connectionString1 = @"Provider=Microsoft.Jet. OLEDB.4.0;Data Source=" + Server.MapPath(strName) + ";Extended Properties=Excel 8.0;";
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open(Server.MapPath(strName), 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindow s, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1) ;
range = xlWorkSheet.UsedRange;
string strDienthoai = "";
string strNoidung = "";
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
Excel.Range temp = (range.Cells[rCnt, cCnt] as Excel.Range);
if (temp.Value2 != null)
{
strDienthoai = temp.Value2.ToString();
}
Vấn đề là file Excel dùng font chữ VNI-Time. Mình đã cài đặt font để view file Excel đọc bình thường.
Nhưng khi đọc file bằng code thì thấy chữ không đọc được. Ví dụ đáng lẽ Nguyễn Văn A thì nó hiển thị chữ lung tung do không đúng font.
Xin hỏi mình phải làm sao để khắc phục vấn đề này?