using System; using System.Collections.Generic; using System.Text; namespace Biff8Excel.Excel { /// /// 用于定义Excel页脚的内容及格式 /// public class ExcelFooter: IDisposable { Biff8Excel.Records.Footer m_footer; StringBuilder m_footerString; internal byte[] WriteRecord() { if (m_footerString.Length == 0) return null ; // make sure the string starts in one of the three sections // in case we forget put it in the left section switch(m_footerString.ToString().Substring(0,2)) { case "&L": case "&C": case "&R": break; default : m_footerString.Append("&L"); break; } m_footer.Foot = Globals.GetUnicodeBytes(m_footerString.ToString()); m_footer.TextLength = (ushort)m_footerString.ToString().Length; return m_footer.GetByte(); } public void AddText(string sText) { if (sText.Length == 0) return; int pos; //Check fot the & character, needs to be duplicated in the string pos = 0; while(true) { pos = sText.IndexOf('&',pos); if (pos < 0) break; //add an extra & character sText = sText.Substring(0,pos+1) + sText.Substring(pos); pos += 2; } m_footerString.Append(sText); } public void SetFont(string fontName) { SetFont(fontName, EnumFontStyle.Regular); } public void SetFont(string fontName, EnumFontStyle fontStyle) { //m_footerstring = m_footerstring.Insert(m_footerstring.Length, "&" + (char)(0x22)); // Quotes //m_footerstring = m_footerstring.Insert(m_footerstring.Length, ","); m_footerString.Append("&" + (char)(0x22)); m_footerString.Append(fontName + ","); // Quotes 双引号 string s =""; switch (fontStyle) { case EnumFontStyle.Regular: s = "Regular"; break; case EnumFontStyle.Bold: s = "Bold"; break; case EnumFontStyle.Italic : s = "Italic"; break; case EnumFontStyle.BoldItalic : s = "Bold Italic"; break; } m_footerString.Append(s + (char)(0x22)); } public void SetFontSize(ushort fontSize) { m_footerString.Append("&" + fontSize.ToString()); } public void StartLeftSection() { m_footerString.Append("&L"); } public void StartCenterSection() { m_footerString.Append("&C"); } public void StartRightSection() { m_footerString.Append("&R"); } public void AddPageNumber() { m_footerString.Append("&P"); } public void AddPageCount() { m_footerString.Append("&N"); } public void AddCurrentDate() { m_footerString.Append("&D"); } public void AddCurrentTime() { m_footerString.Append("&T"); } public void AddSheetName() { m_footerString.Append("&A"); } public void AddFileName() { m_footerString.Append("&F"); } // This is the same for both on and off, but makes code clearer to define then separately public void SetUnderlineOn() { m_footerString.Append("&U"); } public void SetUnderlineOff() { m_footerString.Append("&U"); } public void SetDoubleUnderlineOn() { m_footerString.Append("&E"); } public void SetDoubleUnderlineOff() { m_footerString.Append("&E"); } public void SetStrikeOutOnOff() { m_footerString.Append("&S"); } public void SetSuperScriptOutOnOff() { m_footerString.Append("&X"); } public void SetSubScriptOutOnOff() { m_footerString.Append("&Y"); } public ExcelFooter() { m_footer = new Biff8Excel.Records.Footer(); m_footerString = new StringBuilder(); } #region IDisposable 成员 public void Dispose() { m_footer = null; m_footerString = null; } #endregion } }