C#'ta word dökümanlarınının içeriğini alma

Kodla Büyü

sas7979

Seçkin Üye
Seçkin Üye
Mesajlar
711
Arkadaşlar çeşitli sebeplerle word dökümanlarının içeriğini programınıza dahil etmek isteyebilirsiniz bu yüzden ben bir hayli uğraştım.Bu sıkıntıyı çekmeyin kodları sonunda buldum:)
private void button1_Click_1(object sender, EventArgs e)
{
try
{
OpenFileDialog ofd = new OpenFileDialog();
//making an object for the OpenFileDialog
ofd.Title = "Dosya Seç";
ofd.RestoreDirectory = true;

if (ofd.ShowDialog() == DialogResult.OK)
{

textBox1.Text = ofd.FileName.ToString();
Microsoft.Office.Interop.Word.ApplicationClass wordObject = new Microsoft.Office.Interop.Word.ApplicationClass();
object file = textBox1.Text; //this is the path
object nullobject = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document docs = wordObject.Documents.Open
(ref file, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject,
ref nullobject, ref nullobject, ref nullobject, ref nullobject
);
docs.ActiveWindow.Selection.WholeStory();
docs.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
richTextBox1.Text = data.GetData(DataFormats.Text).ToString();
docs.Close(ref nullobject, ref nullobject, ref nullobject);

}
}Kodlar tamamen çalışmaktadır.Kolay Gelsin :D
 
Eğer C# 4.0 ile bu kodlar yazılırsa, optional parameters kullanılarak bu kadar ref nullobject yazmaya gerek kalmadan bu kodlar kısaltılabilir.
 
BBNET
Geri
Üst