I want to compare two strings with wingdings characters. Because I don't know how to capture wingdings codes in C# strings, then I can't have a realiable comparaison between two strings...
Context : C#/Word
Problem description
I have a word document with a checkbox. This checkbox is a wingding. My challenge is to say if this checkedbox is checked or not using C#.
I know that the checkbow is checked if the hundled string is equal to one of this wingding character x
, ý
and þ
otherwise the checkbox is unchecked.
After your help
After your help, I have a solution to my problem :), Now, I have another problem :))
As I said in the top, all this is to compare the wingding character (checkbox) to all possible wingdings representing a checked checkbox. Now, When I compare directly the checkbox in the word with the encoded wingding I don t find the character because it's encoded in other format...
BUT when I create a word document and I put in the encoded character and then I compare the character I created with the target word doc I HAVE WHAT I WANT :) But this solution as you see need to create a new word doc :(
Any way, here's my solution :)
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Office.Interop.Word;
namespace Project0
{
class Program
{
static bool isChecked(Range rng)
{
var wrdApp = new Application();
wrdApp.Visible = true;
Document wrdDoc = wrdApp.Documents.Add();
Range Rngg = wrdDoc.Paragraphs[1].Range;
Rngg.Font.Name = "WingDings"; // Why I CREATE A SECOND DOC - I Need this font ;(
List<string> list = new List<string>{ "\u00fe", "\u00fd", "\u0078" };
foreach (string k in list)
{
if (rng.Text.Contains(Rngg.Text))
{
return true;
}
}
return false;
}
static void Main(string[] args)
{
List<string> list = new List<string> { "\u00fe", "\u00fd", "\u0078" };
// string wPath = @"C:\DV\test.docx";
// Document wrdDoc = wrdApp.Documents.Open(FileName: wPath, ReadOnly: false);
var wrdApp = new Application();
wrdApp.Visible = true;
Document wrdDoc = wrdApp.Documents.Add();
// I SIMULATE MY DOC
wrdDoc.Paragraphs[1].Range.Font.Name = "WingDings";
wrdDoc.Paragraphs[1].Range.Text = list[1]; // I put a checked box
// CAN I DETERMINE IF THERE IS A CHECKBOX
if (isChecked(wrdDoc.Paragraphs[1].Range))
{
Console.WriteLine("Heeah, there's a checked checkbox !!");
}
}
}
}
Thanks in advance for all your help :)