0

My following C# code in a desktop app on Windows 10 is using office-interop to fetch text from MS WORD 2013 that are bold. Can we achieve the same in a UWP app; if so how?

Microsoft.Office.Interop.Word.Range rng = docs.Content;
Microsoft.Office.Interop.Word.Find find = rng.Find;

find.Font.Bold = 1;
find.Format = true;

List<string> bolds = new List<string>();
while (find.Execute())
{
    bolds.Add(rng.Text);
}
nam
  • 21,967
  • 37
  • 158
  • 332

2 Answers2

1

As per MSDN

Not all Win32 and COM APIs are supported for use in UWP app, see Win32 and COM API

This is API reference for all Windows Runtime namespaces

If you are creating a side-loading app, you can try to use Office interop reference in brokered run time component, see http://blogs.msdn.com/b/wsdevsol/archive/2014/04/14/cheat-sheet-for-using-brokered-windows-runtime-components-for-side-loaded-windows-store-apps.aspx

But you can check DesktopBridgeToUWP-Samples on Microsoft's git page and also see UWP Office Interop sample

Hope helps

msd
  • 591
  • 7
  • 23
  • The [example](https://stefanwick.com/2017/05/26/uwp-calling-office-interop-apis/) from the link you provided looks promising for Excel in that it loads the data to Excel. What I am looking for is a way to read/edit a WORD doc while interacting with a UWP app. Is it possible? – nam Aug 28 '17 at 02:44
  • Did you check the desktop bridge samples? – msd Aug 28 '17 at 07:34
0

You can use OpenXML SDK to read the Word documents (docx/docm/dotx/dotm) from UWP applications. It is available as a NuGet package.

Then you can use LINQ to find the things you need in the document. You can have a look at the example here.

Pavel
  • 910
  • 5
  • 6
  • Do you happen to know how to use OpenXML SDK from UWP. Or may be a link you can point to? – nam Aug 28 '17 at 19:08
  • 1
    I haven't tried it in UWP yet. But it should be almost the same as on the full .Net Framework. As OpenXML SDK 2.7 is compatible with .Net Standard 1.3 which is supported by UWP, you should simply add the latest NuGet package to the project and start working with it. Additionally, if you have compilation issues in the release mode, please see this link https://github.com/OfficeDev/Open-XML-SDK/issues/168 – Pavel Aug 28 '17 at 20:32