Hi Guys,
I am generating Excel file by putting some data's from XML files. In that excel, I want to make a Partial text in Cell into or (not full text).
I used the below code when i used Microsoft.Interop.Excel. it works fine for me. But now i need to do this using CloedXML. I really don't know how to do this. i searched many pages but i didn't get what i required. Can any one tell me the anwser...
- Label:
- Excel.Range rn7 = osheet.Cells[i, 6] as Excel.Range;
- string text = rn7.Text;
- rn7.Select();
- if(rn7.Characters.Count <= 256)
- {
- if (text.Contains(""))
- {
- int startindex = rn7.Text.IndexOf("");
- int endindex = rn7.Text.IndexOf("");
- rn7.Characters[startindex+1, 3].Delete();
- rn7.Characters[endindex-2, 4].Delete();
- rn7.Characters[startindex, (endindex - startindex)-2].Font.Italic = 2;
- }
- if (text.Contains(""))
- {
- int startindex = rn7.Text.IndexOf("");
- int endindex = rn7.Text.IndexOf("");
- rn7.Characters[startindex + 1, 3].Delete();
- rn7.Characters[endindex - 2, 4].Delete();
- rn7.Characters[startindex, (endindex - startindex)-2].Font.Bold = 2;
- }
- if (text.Contains("
" )) - {
- int startindex = rn7.Text.IndexOf("
" ); - int endindex = rn7.Text.IndexOf("");
- rn7.Characters[startindex + 1, 4].Delete();
- rn7.Characters[endindex - 3, 5].Delete();
- rn7.Characters[startindex, (endindex - startindex) - 3].Font.Italic = 2;
- }
- if (text.Contains("
" )) - {
- int startindex = rn7.Text.IndexOf("
" ); - int endindex = rn7.Text.IndexOf("");
- rn7.Characters[startindex + 1, 4].Delete();
- rn7.Characters[endindex - 3, 5].Delete();
- rn7.Characters[startindex, (endindex - startindex) - 2].Font.Name = "Times New Roman";
- }
- rn7.VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
- rn7.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
- text = rn7.Text;
- if (Regex.IsMatch(text,@"\<(b|i|fi|fr)\>"))
- {
- goto Label;
- }
- }
- else
- {
- text = Regex.Replace(text,@"(<(\/)?(fr|fi|b|i)>)","");
- rn7.Value = text;
- }
Abubakr MahdiPosted Aug 10, 2019, 11:30 PM