Не выполняется условие - C# (183633)
Формулировка задачи:
Не могу понять в чем ошибка. При вводе любой буквы всегда выполняется oDoc.Bookmarks["T1"].Range.Text = "М";. Подскажите, пожалуйста, в чем ошибка.
private void SetTemplate(Word._Document oDoc)
{
string s = textBox1.Text;
string p = "а";
if (s.EndsWith(p))
{
oDoc.Bookmarks["T1"].Range.Text = "Ж";
}
else
{
oDoc.Bookmarks["T1"].Range.Text = "М";
}
}Решение задачи: «Не выполняется условие»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
namespace WindowsFormsWordDot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
InitializeComponent();
this.Width = 1300;
this.Height = 650;
}
private void button1_Click(object sender, EventArgs e)
{
Word._Document oDoc = GetDoc(Environment.CurrentDirectory + "\\Dot11.dot"); //Шаблон
oDoc.SaveAs(FileName: Environment.CurrentDirectory + "\\For_print.doc");//Место сохранения документа
oDoc.Close();
}
Word._Application oWord = new Word.Application();
private Word._Document GetDoc(string path)
{
Word._Document oDoc = oWord.Documents.Add(path);
SetTemplate(oDoc);
return oDoc;
}
private void SetTemplate(Word._Document oDoc)
{
string s = textBox1.Text;
string p = "а";
if (s.EndsWith(p))
{
oDoc.Bookmarks["T1"].Range.Text = "Ж";
}
else
{
oDoc.Bookmarks["T1"].Range.Text = "М";
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
}
}