{"id":167,"date":"2022-10-08T11:46:50","date_gmt":"2022-10-08T08:46:50","guid":{"rendered":"https:\/\/kb.astrocroc.com\/?p=167"},"modified":"2022-10-09T16:08:08","modified_gmt":"2022-10-09T13:08:08","slug":"%d0%bf%d1%80%d0%b5%d0%b4%d1%81%d1%82%d0%b0%d0%b2%d0%bb%d0%b5%d0%bd%d0%b8%d0%b5-%d1%81%d0%bf%d0%b8%d1%81%d0%ba%d0%b0-%d1%81-%d0%b4%d0%b8%d0%bd%d0%b0%d0%bc%d0%b8%d1%87%d0%b5%d1%81%d0%ba%d0%be%d0%b9","status":"publish","type":"post","link":"https:\/\/kb.astrocroc.com\/?p=167","title":{"rendered":"\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0432 Excel"},"content":{"rendered":"\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c VisualWebPart<\/p>\n\n\n\n<p>aspx<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-xml\" data-line=\"\">&lt;asp:Panel ID=&quot;FilterPanel&quot; runat=&quot;server&quot;&gt;\n    \n    &lt;asp:Label ID=&quot;_title_lbl&quot; runat=&quot;server&quot; Text=&quot;\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435: &quot;&gt;&lt;\/asp:Label&gt;\n    &lt;asp:TextBox ID=&quot;_title_box&quot; runat=&quot;server&quot;&gt;&lt;\/asp:TextBox&gt;\n    &lt;br\/&gt;&lt;br\/&gt;\n    &lt;asp:Label ID=&quot;_user_lbl&quot; runat=&quot;server&quot; Text=&quot;\u0421\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a: &quot;&gt;&lt;\/asp:Label&gt;\n    &lt;asp:TextBox ID=&quot;_user_box&quot; runat=&quot;server&quot;&gt;&lt;\/asp:TextBox&gt;\n    &lt;br\/&gt;&lt;br\/&gt;\n    &lt;asp:Button ID=&quot;_search_btn&quot; runat=&quot;server&quot; Text=&quot;\u041d\u0430\u0439\u0442\u0438&quot; OnClick=&quot;_search_btn_Click&quot; \/&gt;\n    \n    &lt;asp:Panel ID=&quot;ResultsPanel&quot; runat=&quot;server&quot;&gt;&lt;\/asp:Panel&gt;\n\n&lt;\/asp:Panel&gt;<\/code><\/pre>\n\n\n\n<p>ascx.cs<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-cs\" data-line=\"\">UpdatePanel mainUpdatePanel;\nSPList list;\nListViewWebPart lvwp;\n\nprotected void Page_Load(object sender, EventArgs e)\n{\n    \/\/ \u0421\u043f\u0438\u0441\u043e\u043a\n    list = SPContext.Current.Web.GetList(SPUrlUtility.CombineUrl(SPContext.Current.Web.Url, &quot;Lists\/FiltredList&quot;));\n    \/\/ \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b\n    lvwp = new ListViewWebPart();\n    lvwp.ListName = list.ID.ToString(&quot;B&quot;).ToUpper();\n    lvwp.ViewGuid = list.DefaultView.ID.ToString(&quot;B&quot;).ToUpper();\n    lvwp.ChromeType = PartChromeType.Default;\n\n    mainUpdatePanel = new UpdatePanel();\n    mainUpdatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional;\n\n    mainUpdatePanel.ContentTemplateContainer.Controls.Add(_search_btn);\n    mainUpdatePanel.ContentTemplateContainer.Controls.Add(lvwp);\n\n\n    ResultsPanel.Controls.Add(mainUpdatePanel);\n\n    \/\/ \u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\n    string query = string.Empty;\n    string additionalCondition = &quot;&lt;Or&gt;&lt;Eq&gt;&lt;FieldRef Name=&#039;ID&#039; \/&gt;&lt;Value Type=&#039;Counter&#039;&gt;1&lt;\/Value&gt;&lt;\/Eq&gt;&lt;Eq&gt;&lt;FieldRef Name=&#039;ID&#039; \/&gt;&lt;Value Type=&#039;Counter&#039;&gt;2&lt;\/Value&gt;&lt;\/Eq&gt;&lt;\/Or&gt;&quot;;\n    query = (query.Length &gt; 0 ? &quot;&lt;And&gt;&quot; + query + additionalCondition + &quot;&lt;\/And&gt;&quot; : additionalCondition);\n\n    LoadData(query);\n}\n\n\/\/\/ &lt;summary&gt;\n\/\/\/ \u041a\u043d\u043e\u043f\u043a\u0430 \u043f\u043e\u0438\u0441\u043a\u0430\n\/\/\/ &lt;\/summary&gt;\n\/\/\/ &lt;param name=&quot;sender&quot;&gt;&lt;\/param&gt;\n\/\/\/ &lt;param name=&quot;e&quot;&gt;&lt;\/param&gt;\nprotected void _search_btn_Click(object sender, EventArgs e)\n{\n    string query = string.Empty;\n    string tempAdding = string.Empty;\n    if (!string.IsNullOrEmpty(_title_box.Text))\n    {\n        query = &quot;&lt;Contains&gt;&lt;FieldRef Name=&#039;Title&#039; \/&gt;&lt;Value Type=&#039;Text&#039;&gt;&quot; + _title_box.Text + &quot;&lt;\/Value&gt;&lt;\/Contains&gt;&quot;;\n    }\n    if (!string.IsNullOrEmpty(_user_box.Text))\n    {\n        tempAdding = &quot;&lt;Contains&gt;&lt;FieldRef Name=&#039;Users&#039; \/&gt;&lt;Value Type=&#039;UserMulti&#039;&gt;&quot; + _user_box.Text + &quot;&lt;\/Value&gt;&lt;\/Contains&gt;&quot;;\n        query = (query.Length &gt; 0 ? &quot;&lt;And&gt;&quot; + query + tempAdding + &quot;&lt;\/And&gt;&quot; : tempAdding);\n    }\n\n    \/\/ \u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\n    string additionalCondition = &quot;&lt;Or&gt;&lt;Eq&gt;&lt;FieldRef Name=&#039;ID&#039; \/&gt;&lt;Value Type=&#039;Counter&#039;&gt;1&lt;\/Value&gt;&lt;\/Eq&gt;&lt;Eq&gt;&lt;FieldRef Name=&#039;ID&#039; \/&gt;&lt;Value Type=&#039;Counter&#039;&gt;2&lt;\/Value&gt;&lt;\/Eq&gt;&lt;\/Or&gt;&quot;;\n    query = (query.Length &gt; 0 ? &quot;&lt;And&gt;&quot; + query + additionalCondition + &quot;&lt;\/And&gt;&quot; : additionalCondition);\n\n\n    LoadData(query);\n}\n\n\/\/\/ &lt;summary&gt;\n\/\/\/ \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445\n\/\/\/ &lt;\/summary&gt;\n\/\/\/ &lt;param name=&quot;query&quot;&gt;&lt;\/param&gt;\nprivate void LoadData(string query)\n{\n    XmlDocument doc = new XmlDocument();\n    doc.LoadXml(lvwp.ListViewXml);\n    XmlNode queryNode = doc.SelectSingleNode(&quot;\/\/Query&quot;);\n    XmlNode whereNode = queryNode.SelectSingleNode(&quot;Where&quot;);\n\n    if (whereNode != null) queryNode.RemoveChild(whereNode);\n    XmlNode newNode = doc.CreateNode(XmlNodeType.Element, &quot;Where&quot;, String.Empty);\n    newNode.InnerXml = query.ToString();\n    queryNode.AppendChild(newNode);\n    lvwp.ListViewXml = doc.OuterXml;\n}<\/code><\/pre>\n\n\n\n<p>\u0414\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0432 Excel \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 IE<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\" data-line=\"\">&lt;script language=&quot;javascript&quot; type=&quot;text\/javascript&quot;&gt;\n\tfunction generateexcel() {\n\t\tvar x = document.getElementById(&#039;{7BA8873E-1B90-4EAB-B446-23F93A590249}-{73FEA2BD-79BD-4F55-A8FE-E6DB310018DD}&#039;).rows;\n\t\tvar xls = new ActiveXObject(&quot;Excel.Application&quot;);\n\t\txls.visible = true\n\t\txls.Workbooks.Add\n\t\tfor (i = 0; i &lt; x.length; i++) {\n\t\t\tvar y = x[i].cells;\n\t\t\tfor (j = 0; j &lt; y.length; j++) {\n\t\t\t\txls.cells(i + 1, j + 1).value = y[j].innerText;\n\t\t\t}\n\t\t}\n\t}\n &lt;\/script&gt;\n&lt;input type=&#039;button&#039; value=&#039;Export To Excel&#039; onclick=&quot;generateexcel();&quot;\/&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c VisualWebPart aspx ascx.cs \u0414\u043b\u044f \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0432 Excel \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 IE<\/p>\n","protected":false},"author":1,"featured_media":170,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,11],"tags":[40,28,33],"class_list":["post-167","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-sharepoint","tag-excel","tag-javascript","tag-sharepoint"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"_links":{"self":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":3,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":176,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions\/176"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/media\/170"}],"wp:attachment":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}