private void SetSmartColor(DocumentBuilder documentBuilder, int position, char bit)
        {
            documentBuilder.MoveTo(wordDoc.GetChildNodes(NodeType.Run, true)[wordDoc.GetChildNodes(NodeType.Run, true).Count / 2]);
            var color = ((Run)documentBuilder.CurrentNode).Font.Color;

            var decColor = Convert.ToInt32(Converter.ArgbToHex(color), 16);

            documentBuilder.MoveTo(wordDoc.GetChildNodes(NodeType.Run, true)[position]);

            if (bit == '1')
            {
                decColor += 1;
                ((Run)documentBuilder.CurrentNode).Font.Color = ColorTranslator.FromHtml("#" + decColor.ToString("X"));
            }
            else
            {
                decColor += 2;
                ((Run)documentBuilder.CurrentNode).Font.Color = ColorTranslator.FromHtml("#" + decColor.ToString("X"));
            }
        }
Exemplo n.º 2
0
        private string FindCommonDocColor()
        {
            var    color        = ((Run)wordDoc.GetChildNodes(NodeType.Run, true)[wordDoc.GetChildNodes(NodeType.Run, true).Count / 2]).Font.Color; //перевод из RGB->16->10
            var    decBaseColor = Convert.ToInt32(Converter.ArgbToHex(color), 16);
            string message      = string.Empty;

            foreach (Run run in wordDoc.GetChildNodes(NodeType.Run, true))
            {
                if (decBaseColor + 1 == Convert.ToInt32(Converter.ArgbToHex(run.Font.Color), 16))
                {
                    message += "1";
                }
                else if (decBaseColor + 2 == Convert.ToInt32(Converter.ArgbToHex(run.Font.Color), 16))
                {
                    message += "0";
                }
            }

            return(message);
        }