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
sandy nag
NA
1
1.5k
Copy text(including formats) frm word doc into excel cell
Oct 2 2013 12:14 PM
Hi Guys
I am currently working on excel add-in project, that has search filter. Upon giving search keywords and click on search, it connects sharepoint server and pulls the text/data from word documents located in the directories of sharepoint server and displays in the list box in add-in. I am trying to copy this text from word document and paste into excel cell through programmatically. I can bring the text from word file and show it in excel cell, but could not get the formats that are in word. I appreciate if anyone could throw ideas in resolving this issue.
To make it clear, this should work like copying the text from word document(with formats like underline,bold,itaclicize, font color) and paste as 'keep source formatting' in excel cell.
below is the code I have.
private void InsertItemIntoDocument(SearchResultItem item, ItemInsertionLocation location)
{
Word.Application wordApp = new Word.Application();
object nullobj = System.Reflection.Missing.Value;
try
{
if (item != null)
{
string localFileLoc = this.DownloadFileWithWebClient(item.ContentsUrl);
Word.Document document = wordApp.Documents.Open(localFileLoc.Replace("\\\\", "\\"), Type.Missing, true, false, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
document.ActiveWindow.Selection.WholeStory();
document.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
var content = data.GetData(DataFormats.Text).ToString();
content = content.Replace("\\n\\r", Environment.NewLine);
document.Close();
var ActiveCell = Globals.ThisAddIn.Application.ActiveCell.Address.ToString();
var range = CurrentApplication.Range[ActiveCell];
range.Value2 = content;
range.WrapText = true;
range.EntireColumn.AutoFit();
range.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
range.VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
}
}
Reply
Answers (
0
)
invalid cast
Getting Particular Part Of Website In C#