TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Karthi Keyan
1k
755
237.3k
Update Cell Value in Excel using ClosedXML
Aug 7 2019 1:50 AM
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 <italic> or <bold> (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(
"<i>"
))
{
int
startindex = rn7.Text.IndexOf(
"<i>"
);
int
endindex = rn7.Text.IndexOf(
"</i>"
);
rn7.Characters[startindex+1, 3].Delete();
rn7.Characters[endindex-2, 4].Delete();
rn7.Characters[startindex, (endindex - startindex)-2].Font.Italic = 2;
}
if
(text.Contains(
"<b>"
))
{
int
startindex = rn7.Text.IndexOf(
"<b>"
);
int
endindex = rn7.Text.IndexOf(
"</b>"
);
rn7.Characters[startindex + 1, 3].Delete();
rn7.Characters[endindex - 2, 4].Delete();
rn7.Characters[startindex, (endindex - startindex)-2].Font.Bold = 2;
}
if
(text.Contains(
"<fi>"
))
{
int
startindex = rn7.Text.IndexOf(
"<fi>"
);
int
endindex = rn7.Text.IndexOf(
"</fi>"
);
rn7.Characters[startindex + 1, 4].Delete();
rn7.Characters[endindex - 3, 5].Delete();
rn7.Characters[startindex, (endindex - startindex) - 3].Font.Italic = 2;
}
if
(text.Contains(
"<fr>"
))
{
int
startindex = rn7.Text.IndexOf(
"<fr>"
);
int
endindex = rn7.Text.IndexOf(
"</fr>"
);
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;
}
Reply
Answers (
1
)
Existing excel append
How to detect login users’s device name and Model Number?