示例#1
0
        //用此方法请重写页面的VerifyRenderingInServerForm方法!
        /// <summary>
        /// 导出Office文件Excel或Word文件,HtmoTextWriter方式,用此方法请重写页面的VerifyRenderingInServerForm方法!Office FileType("application/ms-word")("application/ms-excel")
        /// </summary>
        /// <param name="webPage">Web.Page</param>
        /// <param name="webControl">Web表格控件,请重写页面的VerifyRenderingInServerForm方法!</param>
        /// <param name="fileType">Office FileType("application/ms-word")("application/ms-excel")</param>
        /// <param name="fileName">FileFullName</param>
        public void ExportOffice(Page webPage, System.Web.UI.WebControls.WebControl webControl, string fileType, string fileName)
        {
            webPage.Response.Clear();
            webPage.Response.ClearHeaders();
            webPage.Response.Buffer          = false;
            webPage.Response.Charset         = "GB2312";
            webPage.Response.ContentEncoding = System.Text.Encoding.UTF8;
            webPage.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8).ToString().Replace("+", "%20"));
            webPage.Response.ContentType = fileType;
            webPage.EnableViewState      = false;
            StringWriter   tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);

            webControl.RenderControl(hw);
            webPage.Response.Write(tw.ToString());
            webPage.Response.End();
        }
示例#2
0
        public override void Render(HtmlMobileTextWriter writer)
        {
            System.Web.UI.WebControls.WebControl webCalendar = Control.WebCalendar;

            Style.ApplyTo(webCalendar);

            // Delegate the rendering effort to the child Web Calendar
            // control for HTML browser
            webCalendar.Visible = true;

            // There is no explicit property for alignment on WebForms
            // Calendar, so we need some special code to set it.
            writer.EnterLayout(Style);
            writer.EnsureStyle();
            Alignment align = (Alignment)Style[Style.AlignmentKey, true];

            if (!Device.SupportsDivAlign)
            {
                webCalendar.Attributes["align"] = align.ToString();
            }

            if (Device.SupportsCss)
            {
                // Target device supports CSS - simply delegate the rendering
                // to the underlying Web Calendar control
                webCalendar.RenderControl(writer);
            }
            else
            {
                // Insert bgcolor attributes in cells that correspond to selected dates
                StringWriter   sw        = new StringWriter();
                HtmlTextWriter tmpWriter = new HtmlTextWriter(sw);
                webCalendar.RenderControl(tmpWriter);
                String webCalendarHtml = sw.ToString();
                int    index = 0, indexLastTable = 0;
                // Search for offset of last <table> tag in the Web Calendar HTML.
                // That table contains the various days.
                do
                {
                    index = webCalendarHtml.IndexOf(_selectedDateSearchTableTag, index);
                    if (index >= 0)
                    {
                        indexLastTable = index;
                        index         += 5;
                    }
                }while (index >= 0);
                index = LocateNextSelectedDate(webCalendarHtml, indexLastTable);
                if (index >= 0)
                {
                    // Determine the background color of the containing Form control
                    HtmlControlAdapter formAdapter = (HtmlControlAdapter)Control.Form.Adapter;
                    Color backColor = (Color)formAdapter.Style[Style.BackColorKey, true];
                    int   deltaR    = System.Math.Abs(backColor.R - 0xC0);
                    int   deltaG    = System.Math.Abs(backColor.G - 0xC0);
                    int   deltaB    = System.Math.Abs(backColor.B - 0xC0);
                    // Determine the distance between Silver and the Form's background color
                    int bgColorDistance = deltaR * deltaR + deltaG * deltaG + deltaB * deltaB;
                    // Choose Silver or White depending on that distance
                    String selectedDateBGColor =
                        String.Format("bgcolor=\"{0}\" ", bgColorDistance < _bgColorDistanceTreshold ? "White" : "Silver");
                    while (index >= 0)
                    {
                        // Insert the bgcolor attribute for each selected date cell
                        webCalendarHtml = webCalendarHtml.Insert(index + _bgColorInsertionPointInPattern, selectedDateBGColor);
                        index           = LocateNextSelectedDate(webCalendarHtml, index + _bgColorInsertionPointInPattern);
                    }
                }
                // Use the HTML after insertions
                writer.Write(webCalendarHtml);
            }

            if (Control.BreakAfter)
            {
                writer.WriteBreak();
            }
            writer.ExitLayout(Style);
        }