using System; using System.Collections.Generic; using System.Text; namespace Biff8Excel.Excel { public class ExcelPrintSetup: IDisposable { Records.WSBool m_wsBool; Records.Setup m_setup; Records.HCenter m_hCenter; Records.VCenter m_vCenter; Records.TMargin m_tMargin; Records.LMargin m_lMargin; Records.BMargin m_bMargin; Records.RMargin m_rMargin; Records.PrintGridLines m_printGrid; Records.PrintSheetHeaders m_printHeaders; ushort m_wsBoolOptions; ushort m_setupOptions; internal byte[] WriteRecord_SETUP() { m_setup.OptionFlags = m_setupOptions; return m_setup.GetByte(); } internal byte[] WriteRecord_WSBOOL() { m_wsBool.Options = m_wsBoolOptions; return m_wsBool.GetByte(); } internal byte[] WriteRecord_HCENTER() { return m_hCenter.GetByte(); } internal byte[] Writerecord_VCENTER() { return m_vCenter.GetByte(); } internal byte[] Writerecord_TMARGIN() { return m_tMargin.GetByte(); } internal byte[] Writerecord_LMARGIN() { return m_lMargin.GetByte(); } internal byte[] Writerecord_BMARGIN() { return m_bMargin.GetByte(); } internal byte[] Writerecord_RMARGIN() { return m_rMargin.GetByte(); } internal byte[] WriteRecord_PRINTGRID() { return m_printGrid.GetByte(); } internal byte[] WriteRecord_PRINTHEADER() { return m_printHeaders.GetByte(); } public EnumPaperSize PaperSize { set { m_setup.PaperSize = (ushort)value; } } public ushort ScaleFactor { set { m_setup.ScaleFactor = value; m_wsBoolOptions = (ushort)(m_wsBoolOptions & (~0x100)); //sets printout to Scale mode m_wsBool.Options = m_wsBoolOptions; } } public bool StartPage { set { m_setup.StartPage = (ushort)(value ? -1:0); m_setupOptions = (ushort)(m_setupOptions | 0x80); } } public ushort FitPagesWide { set { m_setup.FitPagesWide = value; m_wsBoolOptions = (ushort)(m_wsBoolOptions | 0x100); //sets printout to pages wide mode m_wsBool.Options = m_wsBoolOptions; } } public ushort FitPageHigh { set { m_setup.FitPagesHigh = value; m_wsBoolOptions = (ushort)(m_wsBoolOptions | 0x100); //sets printout to pages wide mode m_wsBool.Options = m_wsBoolOptions; } } public bool PrintPrintBlackAndWhite { set { if (value) m_setupOptions = (ushort)(m_setupOptions | 0x8); else m_setupOptions = (ushort)(m_setupOptions & (~0x8)); } } public bool PrintDraftQuality { set { if (value) { m_setupOptions = (ushort)(m_setupOptions | 0x10); } else { m_setupOptions = (ushort)(m_setupOptions & (~0x10)); } m_setup.HorizontalDpi = 300; m_setup.VerticalDpi = 300; } } public EnumPaperOrientation Orientation { set { if (value == EnumPaperOrientation.Portrait) m_setupOptions = (ushort)(m_setupOptions | 0x2); else m_setupOptions = (ushort)(m_setupOptions & (~0x2)); } } public bool CenterHorizontally { set { m_hCenter.Center = (ushort)(value ? 1 : 0); } } public bool CenterVertically { set { m_vCenter.Center = (ushort)(value ? 1 : 0); } } /// /// 打印时是否加上表格线 /// public bool PrintGridLines { set { m_printGrid.PrintLines = (ushort)(value ? 1 : 0); } } public bool PrintHeaders { set { m_printHeaders.PrintHeaders = (ushort)(value ? 1 : 0); } } public double HeaderMargin { set { m_setup.HeaderMargin = value / 2.5; } } public double FooterMargin { set { m_setup.FooterMargin = value / 2.5; } } public ushort Copies { set { m_setup.Copies = value; } } public double TopMargin { set { m_tMargin.Value = value / 2.5; } } public double LeftMargin { set { m_lMargin.Value = value / 2.5; } } public double BottomMargin { set { m_bMargin.Value = value / 2.5; } } public double RightMargin { set { m_rMargin.Value = value / 2.5; } } public ExcelPrintSetup() { m_setup = new Biff8Excel.Records.Setup(); m_wsBool = new Biff8Excel.Records.WSBool(); m_hCenter = new Biff8Excel.Records.HCenter(); m_vCenter = new Biff8Excel.Records.VCenter(); m_tMargin = new Biff8Excel.Records.TMargin(); m_lMargin = new Biff8Excel.Records.LMargin(); m_bMargin = new Biff8Excel.Records.BMargin(); m_rMargin = new Biff8Excel.Records.RMargin(); m_printGrid = new Biff8Excel.Records.PrintGridLines(); m_printHeaders = new Biff8Excel.Records.PrintSheetHeaders(); // default values m_wsBoolOptions = (ushort)(m_wsBoolOptions | 0x1); // Show automatic page breaks m_wsBoolOptions = (ushort)(m_wsBoolOptions | 0x40); // outline buttons below outline group m_wsBoolOptions = (ushort)(m_wsBoolOptions | 0x80); // outline buttons right of outline group // default settings m_setup.PaperSize = 9; // A4 m_setup.ScaleFactor = 100; // 100 percent m_setup.HorizontalDpi = 600; m_setup.VerticalDpi = 600; m_setup.Copies = 1; m_setup.FitPagesHigh = 1; m_setup.FitPagesWide = 1; m_setup.StartPage = 1; m_setup.HeaderMargin = 0.5; m_setup.FooterMargin = 0.5; m_setupOptions = (ushort)(m_setupOptions | 0x2); // Portrait m_setup.OptionFlags = m_setupOptions ; // default margins m_tMargin.Value = 1; m_lMargin.Value = 0.7; m_bMargin.Value = 1; m_rMargin.Value = 0.7; } #region IDisposable 成员 public void Dispose() { m_setup = null; m_wsBool = null; m_hCenter = null; m_vCenter = null; m_tMargin = null; m_lMargin = null; m_bMargin = null; m_rMargin = null; m_printGrid = null; m_printHeaders = null; } #endregion } }