<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Neysor.net &#187; C#</title>
	<atom:link href="http://www.neysor.net/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.neysor.net</link>
	<description>about everything i like :)</description>
	<lastBuildDate>Sun, 29 Jan 2012 15:31:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>iTunes DJ &#8211; Erster Versuch</title>
		<link>http://www.neysor.net/2011/07/itunes-dj-erster-versuch/</link>
		<comments>http://www.neysor.net/2011/07/itunes-dj-erster-versuch/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 14:18:42 +0000</pubDate>
		<dc:creator>Neysor</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[COM-Interface]]></category>
		<category><![CDATA[iTunes]]></category>
		<category><![CDATA[iTunes DJ]]></category>

		<guid isPermaLink="false">http://www.neysor.net/?p=897</guid>
		<description><![CDATA[Vor kurzem habe ich mich entschlossen, alle meine Lieder in iTunes zu verwalten. Eigentlich konnte ich diese Software nie leiden. Ich war der Typ der alles in selbstverwalteten Ordner gehortet hat Doch mittlerweile mit iPhone, iPad und co. habe ich mich irgendwie auch verleiten lassen alles in dieser Software zu verwalten. Dabei bin ich dann [...]]]></description>
			<content:encoded><![CDATA[<p>Vor kurzem habe ich mich entschlossen, alle meine Lieder in iTunes zu verwalten. Eigentlich konnte ich diese Software nie leiden. Ich war der Typ der alles in selbstverwalteten Ordner gehortet hat <img src='http://www.neysor.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Doch mittlerweile mit iPhone, iPad und co. habe ich mich irgendwie auch verleiten lassen alles in dieser Software zu verwalten. Dabei bin ich dann auch auf iTunes DJ gestoßen. Die Idee ist super. Ein shuffle Modus über die ganze Musik. Aber das beste ist das VOTING System für alle Benutzer. Leider auf iOS beschränkt.</p>
<p>Damit man aber wenigstens das aktuelle Lied auf einem anderen Gerät im Browser sehen kann, habe ich mich entschlossen mit der COM-Library zu spielen. Die Doku ist recht gut und mein erster Versuch hat auch sehr gut geklappt.</p>
<p>Nächstes und Vorheriges Lied sind 2-Zeiler:</p>
<pre class="brush: csharp; title: ; notranslate">

iTunesLib.iTunesApp app = new iTunesAppClass();
 app.PreviousTrack();
//app.NextTrack();
</pre>
<p>Aber auch das anzeigen der Playliste und des Covers des aktuellen Liedes ging sehr einfach. Hier der code:</p>
<pre class="brush: csharp; title: ; notranslate">

iTunesLib.iTunesApp app = new iTunesAppClass();

 String id = app.CurrentPlaylist.playlistID.ToString();
 String name = app.CurrentPlaylist.Name;
 IITTrackCollection c = app.CurrentPlaylist.Tracks;
 IITArtwork Art = c.get_ItemByPlayOrder(6).Artwork[1];
 pictureBox1.Image = null;
 pictureBox1.Invalidate();
 Art.SaveArtworkToFile(&quot;c:\\tmp\\Album.jpg&quot;);
 pictureBox1.Image = null;
 Stream stream = File.Open(&quot;c:\\tmp\\Album.jpg&quot;,FileMode.Open);
 Image temp = Image.FromStream(stream);
 stream.Close();
 pictureBox1.Image = temp;
 String s = &quot;&quot;;
 for (int i = 1; i &gt;= c.Count; i++)
      {
      IITTrack t = c.get_ItemByPlayOrder(i);
      if (t.trackID == app.CurrentTrack.trackID) {  s += &quot;&gt;&gt; &quot;;  }
      s += t.Name + &quot;\n&quot;;
 }
 richTextBox1.Text = &quot;Playlistname:&quot;+name+&quot;\nLieder&quot; + s;
</pre>
<p><a class="fancybox" href="http://www.neysor.net/wp-content/uploads/2011/07/screeny.png" rel="lightbox[897]" title="screeny"><img class="size-medium wp-image-904 aligncenter" title="screeny" src="http://www.neysor.net/wp-content/uploads/2011/07/screeny-300x174.png" alt="" width="300" height="174" /></a></p>
<p>Das war nur mein erster kruzer Versuch und ich hoffe ihr könnt damit was anfangen. Wenn ich dann mich zu einem schöneren Beispiel überwunden habe, werde ich natürlich bessere Erklärungen zu diesen Code liefern. Aber eigentlich sollte es eh recht klar sein was hier passiert <img src='http://www.neysor.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="addthis_toolbox addthis_default_style" addthis:url='http://www.neysor.net/2011/07/itunes-dj-erster-versuch/' addthis:title='iTunes DJ &#8211; Erster Versuch' ><a class="addthis_button_twitter"></a><a class="addthis_button_email"></a><a class="addthis_button_facebook"></a><a class="addthis_button_google"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.neysor.net/2011/07/itunes-dj-erster-versuch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excel mit C# lesen</title>
		<link>http://www.neysor.net/2009/05/excel-mit-c-sharp-lesen/</link>
		<comments>http://www.neysor.net/2009/05/excel-mit-c-sharp-lesen/#comments</comments>
		<pubDate>Mon, 25 May 2009 21:25:26 +0000</pubDate>
		<dc:creator>Neysor</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://blog.neysor.net/?p=121</guid>
		<description><![CDATA[In einem Ferialpraktikum hatte ich einmal das Problem, dass ich eine Exceldatei aus einer C# Anwendung lesen musste. Dazu habe ich mir 2 Klassen geschrieben. myExcelApplication, welches mir eine Instanz von Microsoft Excel öffnet und nach Beendigung wieder schließt. Und myWorkbook, welche mir den Zugriff auf ein Workbook ermöglicht. Wichtig sind vor allem die Referenzen. [...]]]></description>
			<content:encoded><![CDATA[<p>In einem Ferialpraktikum hatte ich einmal das Problem, dass ich eine Exceldatei aus einer C# Anwendung lesen musste. Dazu habe ich mir 2 Klassen geschrieben. <strong>myExcelApplication</strong>, welches mir eine Instanz von <a href="http://office.microsoft.com/de-at/excel/" title="Microsoft Excel" target="_blank">Microsoft Excel</a> öffnet und nach Beendigung wieder schließt. Und <strong>myWorkbook</strong>, welche mir den Zugriff auf ein Workbook ermöglicht.</p>
<p>Wichtig sind vor allem die Referenzen. Man muss <strong>Microsoft.Office.Core</strong> sowie <strong>Microsoft.Office.Interop.Excel</strong> einbinden, damit es sicher funktioniert <img src='http://www.neysor.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: csharp; collapse: true; light: false; title: ; toolbar: true; notranslate">
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices; //Für DllImport!
using System.Diagnostics; //Für Process
</pre>
<p><strong>myExcelApplication:</strong></p>
<pre class="brush: csharp; collapse: true; light: false; title: ; toolbar: true; notranslate">
public class myExcelApplication : IDisposable
{
	#region user32 Funktionen
	// Windows OS Funktionen deklarieren
	[DllImport(&quot;user32&quot;)]
	private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

	[DllImport(&quot;user32.dll&quot;, SetLastError = true)]
	static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);

	// Ende Os Funktionen
	#endregion

	public Excel.ApplicationClass ExApp; //Besitzt alle Excelfunktionen
	private string ApplicationID; //Ist meine Programmid
	private IntPtr hWnd; // Window Handle
	private int iProcID; // Prozess ID des markierten EXCELs
	private Process p = null; // entsprechendes Process object
	public myExcelApplication()
	{
		//defaulteinstellungen
		System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(&quot;en-US&quot;);
		this.ApplicationID = &quot;Excel_&quot; + System.Guid.NewGuid().ToString().ToUpper(); //ID erzeugen
		this.ExApp = new Excel.ApplicationClass(); //Excelklasse zuweisen
		this.ExApp.DisplayAlerts = false; //keine Warnmeldungen Anzeigen
		this.ExApp.AskToUpdateLinks = false; //Updateabfrage deaktivieren
		this.ExApp.Visible = false; //unsichtbar
		this.ExApp.Caption = this.ApplicationID; //Id zuweisen

	}
	~myExcelApplication()
	{
		this.Dispose();
	}

	#region IDisposable Members

	public void Dispose()
	{
		/*
		 * Folgendes funktioniert nicht:
		 * ExApp.Application.Quit(); oder this.ExApp.Quit();
		 * Leider weiß ich nicht mehr woher ich das habe.
		 * Aber deswegen haben wir die EXCEL Applikation markiert
		 */
		hWnd = FindWindow(null, ApplicationID);
		if (hWnd == IntPtr.Zero) return;
		// zu dem Fenster holen wir uns die Prozess-ID ...
		GetWindowThreadProcessId(hWnd, out iProcID);
		if (iProcID == 0) return;
		// erzeugen ein entsprechendes .NET Prozess Objekt ..
		p = Process.GetProcessById((int)iProcID);
		if (p == null) return;
		// jetzt ist Feierabend ...
		p.CloseMainWindow();    // schliesse Fenster
		p.Refresh();            // gebe alle Prozess-Informationen frei
		if (p != null)
		{
			p.Kill();               // und tschuess ...
		}
	}

	#endregion
}
</pre>
<p><strong>myWorkbook:</strong></p>
<pre class="brush: csharp; collapse: true; light: false; title: ; toolbar: true; notranslate">
public class myWorkbook
{
	public Excel.Workbook myWb;
	public string Datei;
	public myExcelApplication ExApp;
	public bool schreibschutz = false;
	private bool _calculation;
	public bool calculation
	{
		get { return this._calculation; }
		set
		{
			this._calculation = value;
			this.calculate();
		}
	}
	public string aktivsheet;

	public myWorkbook(string datei, myExcelApplication EApp)
	{
		this.Datei = datei;
		this.ExApp = EApp;
	}
	public myWorkbook()
	{
		//leerer konstruktor
	}
	public void open()
	{
		try
		{
			this.myWb = ExApp.ExApp.Workbooks.Open(this.Datei, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
		}
		catch (Exception e)
		{
			//
		}
		//this.myWb = ExApp.ExApp.Workbooks.Open(this.Datei, 0, true, 5, &quot;&quot;, &quot;&quot;, true,Excel.XlPlatform.xlWindows, &quot;t&quot;, false, false, 0, true, false, false);

		if (this.myWb.ReadOnly) { this.schreibschutz = true; }
		this.calculation = false; //Abschalten der automatischen Berechnung
	}
	public void close()
	{
		object Save = Excel.XlSaveAction.xlSaveChanges; //Speichern oder nicht speichern Variable hier setzen
		this.calculation = true; //Noch einmal schnell rechnen lassen vorm schließen
		this.myWb.Close(Save, Type.Missing, Type.Missing); //schließen
	}
	private void calculate()
	{
		//Schaltet automatische Berechnung ab bzw. aktiviert sie wieder
		if (!this.calculation)
		{
			this.ExApp.ExApp.Calculation = Excel.XlCalculation.xlCalculationManual;
		}
		else
		{
			this.ExApp.ExApp.Calculation = Excel.XlCalculation.xlCalculationAutomatic;
			this.ExApp.ExApp.Calculate();
		}
	}
	public Excel.Range Zelle(int Zeile, int Spalte)
	{
		return (Excel.Range)((Excel.Worksheet)this.myWb.Worksheets[this.aktivsheet]).Cells[Zeile, Spalte];
	}
	public Excel.Range Zelle(int Zeile, int Spalte, string Worksheet)
	{
		return (Excel.Range)((Excel.Worksheet)this.myWb.Worksheets[Worksheet]).Cells[Zeile, Spalte];
	}
}
</pre>
<p>Hier ein Beispiel, wie man mit diesen Klassen, die Erste Zelle des Blattes &#8220;Tabelle1&#8243; auslesen kann:</p>
<pre class="brush: csharp; title: ; notranslate">
//Applikation starten
myExcelApplication EApp = new myExcelApplication();
//Workbook erzeugen
myWorkbook ExcelFile = new myWorkbook(&quot;c:\test.xls&quot;, EApp);
//Excelfile öffnen
ExcelFile.open();
//Sheet wählen
ExcelFile.aktivsheet = &quot;Tabelle1&quot;;
//Zeile auslesen
String zelle1 = ExcelFile.Zelle(1, 1).Value2;
//Workbook schließen
ExcelFile.close();
//Applikation schließen
EApp.Dispose();
</pre>
<p><em><strong>Tipp:</strong></em> Schaltet die automatische Berechnung von Zellen ab und erst kurz vorm speichern wieder an. Das spart oftmals wertvolle Rechenzeit <img src='http://www.neysor.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="addthis_toolbox addthis_default_style" addthis:url='http://www.neysor.net/2009/05/excel-mit-c-sharp-lesen/' addthis:title='Excel mit C# lesen' ><a class="addthis_button_twitter"></a><a class="addthis_button_email"></a><a class="addthis_button_facebook"></a><a class="addthis_button_google"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.neysor.net/2009/05/excel-mit-c-sharp-lesen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

