mapping between two text file contain arabic characters c#
I have text file contains data like as:
ID 1 Name Mary Mark 89 ID 2 Name Mai Mark 67
and I have another txt file contains data : ID Mobile 1 0993209320 2
0943043094
I want to create excel file which contains only two columns: Mobile
Message 0993209320 ID 1 Name Mary Mark 89 0943043094 ID 2 Name Mai Mark 67
to do this,I tried the following code, it works fine, and the required
excel file was created, but when I change the data contained in both text
file to Arabic, the code created excel file, but Empty, what should I do
to modify the code to make it able to deal with arabic character??
this is the code:
DataTable dtMapping = new DataTable();
ArrayList lstMapping = new ArrayList();
dtMapping.Columns.Add("Mobile"); dtMapping.Columns.Add("Message");
string[] readFile1 = File.ReadAllLines(Location of 1st file);
string[] readFile2 = File.ReadAllLines(Location of 2nd file);
for (int i = 0; i < readFile1.Length; i++)
{
string fileData = readFile1[i].ToString();
int find_Id_Index = fileData.IndexOf("ID ");
if (find_Id_Index != -1)
{
int find_Name_Index = fileData.IndexOf("Name ",
find_Id_Index);
string id =
fileData.Substring(find_Id_Index+3,find_Name_Index-(find_Id_Index+3)
).Trim();
lstMapping.Add("ID " + id);
lstMapping.Add(fileData.Substring(find_Name_Index,
fileData.Length - (find_Name_Index)).Trim());
}
}
for (int i = 1; i < readFile2.Length; i++)
{
int find_Space_Index = readFile2[i].IndexOf(" ");
if (find_Space_Index != -1)
{
string file2id = readFile2[i].Substring(0,
find_Space_Index).Trim();
string mobileno =
readFile2[i].Substring(find_Space_Index,
readFile2[2].Length - (find_Space_Index -
file2id.Length+1)).Trim();
int find_Id = lstMapping.IndexOf("ID " + file2id);
if (find_Id != -1)
{
dtMapping.Rows.Add(mobileno, "ID " + file2id + " "
+ lstMapping[find_Id + 1]);
}
}
}
Microsoft.Office.Interop.Excel.Application excelApp = new
Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook =
excelApp.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
Microsoft.Office.Interop.Excel.Worksheet workSheet =
(Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1];
for (int i = 0; i < dtMapping.Columns.Count; i++)
{
workSheet.Cells[1, (i + 1)] =
dtMapping.Columns[i].ColumnName;
}
for (int i = 0; i < dtMapping.Rows.Count; i++)
{
for (int j = 0; j < dtMapping.Columns.Count; j++)
{
workSheet.Cells[(i + 2), (j + 1)] = dtMapping.Rows[i][j];
}
}
excelApp.Visible = true;
No comments:
Post a Comment