Interop etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Interop etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

4 Nisan 2018 Çarşamba

Outlook Interop

AddressList Sınıfı
Constructor 
Şöyle yaparız.
AddressLists als = ...;
foreach (AddressList addrList in als) {...}
Name Alanı
Şöyle yaparız.
if (addrList.Name == "Global Contact Address" ||
    addrList.Name == "Global Address List")
{...}
AddressEntry Sınıfı
Constructor 
Şöyle yaparız.
AddressList addrList = ...;
foreach (AddressEntry entry in addrList.AddressEntries {...}
Address Alanı
Şöyle yaparız.
if (entry.Address == null) {...}
GetExchangeUser metodu
Şöyle yaparız.
ExchangeUser user = entry.GetExchangeUser();
Name Alanı
Şöyle yaparız.
if (entry.Name == null) {...}
Application Sınıfı
Constructor
Şöyle yaparız.
Outlook.Application outlook = new Outlook.Application();
GetNamespace metodu
Şöyle yaparız.
Outlook.NameSpace mapiNameSpace = outlook.GetNamespace("MAPI");
Item Sınıfı
Delete metodu
Şöyle yaparız.
for (int i = outlookCalenderItems.Count; i > 0; i--)
{
  if (outlookCalenderItems[i].Subject.Contains("On Call: Regions:"))
  {
    outlookCalenderItems[i].Delete();
  }
}
MailItem Sınıfı
Forward metodu
Elimizde bir e-post olsun.
Microsoft.Office.Interop.Outlook.MailItem  mailItem = ...;
Şöyle yaparız.
var newItem = mailItem.Forward();
newItem.Recipients.Add("to.alt@web.de");
newItem.Send();
MAPIFolder Sınıfı
Items Alanı
Şöyle yaparız.
Outlook.Items outlookCalendarItems = calendarFolder.Items;
NameSpace Sınıfı
GetDefaultFolder metodu
Şöyle yaparız.
Outlook.MAPIFolder calendarFolder = mapiNameSpace.GetDefaultFolder
  (Outlook.OlDefaultFolders.olFolderCalendar);



29 Ocak 2017 Pazar

Word Interop

Namespace
Word için kullanılan tüm sınıflar şu namespace içinde
Microsoft.Office.Interop.Word
Şöyle de yapabiliriz.
using word = Microsoft.Office.Interop.Word;
Application Sınıfı
Constructor
Şöyle yaparız.
Word.Application wordApplication = new Word.Application();
Visible Alanı
Şöyle yaparız.
wordApplication.Visible = false;
Document Sınıfı
Add metodu
missing şöyle tanımlıdır.
object missing = System.Type.Missing;
Şöyle de tanımlanabiliyor.
Object missing = System.Reflection.Missing.Value;
Boş bir dosya şöyle yaratılır.
// Create a new file
Document wordDocument = word.Documents.Add(ref missing
                                         , ref missing
                                         , ref missing
                                         , ref missing);
Content Alanı
Şöyle yaparız.
MsWord.Document wordDocument = ...;
MsWord.Range oRange = wordDocument.Content;
oRange.Copy();
Open metodu
Bu metod 16 tane yani bir sürü parametre alabiliyor.
1. parametre FilePath - Dosya yolu
2. parametre ConfirmConversion - html dosyasını çevirerek açmak için gerekir.
3. parametre ReadOnly - Dosyayı salt okunur açar. Aynı isimle kaydedilemez.
5. parametre ReadOnlyPassword - Şifreyle korunan dosyayı okumak için gerekir.
8. parametre WriteOnlyPassword - Dosyanın aynı isimle kaydedilmesini engeller.

Mevcut bir Word dosyası şöyle açılır.
Application word = new Application(); 
Document document = word.Documents.Open(@"C:\Test\NewDocument.docx);
Bir başka örnek

Document doc = word.Documents.Open(FilePath, false, true);

Boş bir Word dosyası şöyle yaratılır.
using System;
using Microsoft.Office.Interop.Word;

class Program
{
  static void Main()
  {
    // Open a doc file.
    Application word = new Application();
    Document document = word.Documents.Open("C:\\word.doc");

    //Do whatever you want

    // Close word.
    word.Quit();
  }
}
Close Metodu

Kapatmak için şöyle yaparız

document.Close();
Eğer dosyayı kaydetmeden kapatmak istersek şöyle yaparız.

object doNotSave = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
document.Close(ref doNotSave);
SaveAs Metodu
Bu metod 16 tane yani bir sürü parametre alabiliyor. 
1. parametre - Kaydedilecek dosya yolur
2. parametre - Kaydetme formatı
PDF olarak kaydetmek için şöyle yaparız.
object fileFormat = WdSaveFormat.wdFormatPDF;
Doc formatında açılan bir dosyayı docx olarak kaydetmek için şöyle yaparız.
document.SaveAs(outputpath, WdSaveFormat.wdFormatXMLDocument);
14 parametre - Allow Substitution sanırım mevut dosyanın üzerine yazmak için gerekir.

Paragraph Sınıfı
Şöyle dolaşırız.

for (int i = 0; i < docs.Paragraphs.Count; i++)
{
  text.Append(" \r\n " + docs.Paragraphs[i + 1].Range.Text.ToString());
}
Section Sınıfı
Section'lar şöyle dolaşılır.
foreach (Section section in doc.Sections)
{...}
Linq ile şöyle yaparız.
List<Section> sections = new List<Section>(doc.Sections.Cast<Sections>());
Section'a header şöyle atanır.
Section sec = doc.Sections[indexValue]
HeaderFooter hf = sec.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary];
hf.LinkToPrevious = false;
hf.Range.Text = "Content for this header";

Selection Sınıfı
constructor 
Şöyle yaparız.
Word.Selection selection = word.Selection;
InsertBreak metodu
Şöyle yaparız.
object pageBreak = Word.WdBreakType.wdSectionBreakNextPage;
selection.InsertBreak(ref pageBreak);
InsertFile metodu
missin şöyle tanımlıdır.
object missing = System.Type.Missing;
Şöyle yaparız.
string file = ...;

selection.InsertFile(file
                   , ref missing
                   , ref missing
                   , ref missing
                   , ref missing);