{"id":182,"date":"2011-01-11T11:42:02","date_gmt":"2011-01-11T10:42:02","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=182"},"modified":"2011-01-11T11:55:34","modified_gmt":"2011-01-11T10:55:34","slug":"asp-net-und-c-excel-dateien-im-web-darstellen","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=182","title":{"rendered":"ASP.NET und C#: Excel Dateien im Web darstellen"},"content":{"rendered":"<h1>Aufgabenstellung<\/h1>\n<p>Eine Excel Datei, die in einer Firma st\u00e4ndig aktualisiert wird, soll auf Smart Phones (Blackberrys, iPhones, Windows Mobiles, HTCs &#8230;) abrufbar sein. <\/p>\n<h1>Vorraussetzungen<\/h1>\n<p>Vorweg solllte der Artikel &#8222;WebDAV mit IIS einrichten&#8220; durchgearbeitet werden, um Zugriff zu bekommen.<\/p>\n<h1>Ansatz<\/h1>\n<p>Die Datei wird ortstransparent auf einem WebDAV-Laufwerk (siehe Artikel WebDAV einrichten) eines Microsoft IIS Server gespeichert, der nach dem Verfahren von Artikel &#8222;WebDAV einrichten&#8220; konfiguriert ist.. Der Microsoft JET Treiber verf\u00fcgt \u00fcber die F\u00e4higkeiten, Excel Dateien zu laden (nur XLS, nicht XLSX oder XLSM). Im IIS Server wird eine ASP.NET Anwendung angelegt. Das nachfolgende Beispiel ist so eingerichtet, das es versuchen wird aus dem Web Root der Anwendung eine Datei test.xls zu laden.<\/p>\n<h1>L\u00f6sung<\/h1>\n<p>Anlegen eine ASP.NET Seite:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot;  \r\nCodeFile=&quot;Default.aspx.cs&quot; Inherits=&quot;_Default&quot; %&gt;\r\n\r\n&lt;!DOCTYPE html PUBLIC &quot;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&quot; \r\n&quot;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&quot;&gt;\r\n\r\n&lt;html xmlns=&quot;http:\/\/www.w3.org\/1999\/xhtml&quot; &gt;\r\n&lt;head runat=&quot;server&quot;&gt;\r\n    &lt;title&gt;Unbenannte Seite&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;\r\n    &lt;div&gt;\r\n        &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot;&gt;\r\n        &lt;\/asp:GridView&gt;\r\n        &amp;nbsp;&lt;\/div&gt;\r\n        &lt;asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text=&quot;Label&quot;&gt;&lt;\/asp:Label&gt;\r\n    &lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>&#8230; mit dem folgenden Code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nusing System;\r\nusing System.Data;\r\nusing System.Configuration;\r\nusing System.Web;\r\nusing System.Web.Security;\r\nusing System.Web.UI;\r\nusing System.Web.UI.WebControls;\r\nusing System.Web.UI.WebControls.WebParts;\r\nusing System.Web.UI.HtmlControls;\r\nusing System.Data.OleDb;\r\n\r\npublic partial class _Default : System.Web.UI.Page \r\n{\r\n    protected void Page_Load(object sender, EventArgs e)\r\n    {\r\n\r\n        string appPath = HttpContext.Current.Request.ApplicationPath;\r\n        string physicalPath = HttpContext.Current.Request.MapPath(appPath).\r\n                                                         Replace(&quot;\\\\&quot;,&quot;\\\\\\\\&quot;);\r\n\r\n        string ConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0; \r\n        Data Source=&quot;+physicalPath+&quot;\\\\test.xls; Extended Properties=&quot;+\r\n                                                              \\&quot;Excel 8.0;HDR=Yes\\&quot;;&quot;;\r\n\r\n        string CommandText = &quot;select * from &#x5B;Tabelle1$]&quot;;\r\n\r\n        OleDbConnection myConnection = new OleDbConnection(ConnectionString);\r\n        OleDbCommand myCommand = new OleDbCommand(CommandText, myConnection);\r\n\r\n        myConnection.Open();\r\n\r\n        GridView1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);\r\n        GridView1.DataBind();\r\n\r\n        myConnection.Close();\r\n\r\n        Label1.Text = physicalPath;\r\n    }\r\n}\r\n<\/pre>\n<h1>Beispiel<\/h1>\n<p>Diese Datei kann per WebDAV bearbeitet werden:<br \/>\nhttp:\/\/178.77.69.22\/test.xls<\/p>\n<p>und wird on-the-fly in eine HTML-Seite umgewandelt:<br \/>\nhttp:\/\/178.77.69.22\/exceltoweb\/Default.aspx<\/p>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D182&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Aufgabenstellung Eine Excel Datei, die in einer Firma st\u00e4ndig aktualisiert wird, soll auf Smart Phones (Blackberrys, iPhones, Windows Mobiles, HTCs &#8230;) abrufbar sein. Vorraussetzungen Vorweg solllte der Artikel &#8222;WebDAV mit IIS einrichten&#8220; durchgearbeitet werden, um Zugriff zu bekommen. Ansatz Die Datei wird ortstransparent auf einem WebDAV-Laufwerk (siehe Artikel WebDAV einrichten) eines Microsoft IIS Server gespeichert, &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=182\" class=\"more-link\"><span class=\"screen-reader-text\">ASP.NET und C#: Excel Dateien im Web darstellen<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-182","post","type-post","status-publish","format-standard","hentry","category-net"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-2W","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=182"}],"version-history":[{"count":8,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/182\/revisions"}],"predecessor-version":[{"id":190,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/182\/revisions\/190"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}