-
October 2nd, 2013, 10:59 AM
#1
Copy text from word (including formats bold,underline,highlighted areas)into excelcel
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;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|