Example #1
0
        // read print settings from sheet, show in form
        private void ShowPrintSettings()
        {
            XLSheet         sheet = c1XLBook1.Sheets[0];
            XLPrintSettings ps    = sheet.PrintSettings;

            // paper size, orientation
            _cmbPaperSize.SelectedItem = ps.PaperKind;
            if (ps.Landscape)
            {
                _rdLandscape.Checked = true;
            }
            else
            {
                _rdPortrait.Checked = true;
            }

            // scaling
            if (ps.AutoScale)
            {
                _rdFit.Checked = true;
            }
            else
            {
                _rdAdjust.Checked = true;
            }
            _udAcross.Value      = ps.FitPagesAcross;
            _udDown.Value        = ps.FitPagesDown;
            _udPercentSize.Value = ps.ScalingFactor;

            // start page
            _txtStartPage.Text = ps.StartPage.ToString();

            // margins
            _udLeft.Value   = new decimal(ps.MarginLeft);
            _udTop.Value    = new decimal(ps.MarginTop);
            _udRight.Value  = new decimal(ps.MarginRight);
            _udBottom.Value = new decimal(ps.MarginBottom);
            _udHeader.Value = new decimal(ps.MarginHeader);
            _udFooter.Value = new decimal(ps.MarginFooter);

            // header/footer
            _txtHeader.Text = ps.Header;
            _txtFooter.Text = ps.Footer;
        }
Example #2
0
        // read print settings from form, apply to sheet
        private void ApplyPrintSettings()
        {
            XLSheet         sheet = c1XLBook1.Sheets[0];
            XLPrintSettings ps    = sheet.PrintSettings;

            // paper size, orientation
            if (_cmbPaperSize.SelectedItem != null)
            {
                ps.PaperKind = (PaperKind)_cmbPaperSize.SelectedItem;
            }
            ps.Landscape = _rdLandscape.Checked;

            // scaling
            // ** note:
            //    setting the FitPagesAcross, FitPagesDown, and ScalingFactor properties
            //    changes the value of AutoScale, so set AutoScale last.
            ps.FitPagesAcross = decimal.ToInt32(_udAcross.Value);
            ps.FitPagesDown   = decimal.ToInt32(_udDown.Value);
            ps.ScalingFactor  = decimal.ToInt32(_udPercentSize.Value);
            ps.AutoScale      = _rdFit.Checked;

            // start page
            try
            {
                ps.StartPage = int.Parse(_txtStartPage.Text);
            }
            catch
            {
                ps.StartPage = 1;
            }

            // margins
            ps.MarginLeft   = decimal.ToDouble(_udLeft.Value);
            ps.MarginTop    = decimal.ToDouble(_udTop.Value);
            ps.MarginRight  = decimal.ToDouble(_udRight.Value);
            ps.MarginBottom = decimal.ToDouble(_udBottom.Value);
            ps.MarginHeader = decimal.ToDouble(_udHeader.Value);
            ps.MarginFooter = decimal.ToDouble(_udFooter.Value);

            // header/footer
            ps.Header = _txtHeader.Text;
            ps.Footer = _txtFooter.Text;
        }