示例#1
0
 /// <summary>
 /// Take a cell, and apply a font to it
 /// </summary>
 /// <param name="cell">the cell to Set the alignment for</param>
 /// <param name="workbook">The workbook that is being worked with.</param>
 /// <param name="font">The HSSFFont that you want to Set...</param>
 public static void SetFont(ICell cell, HSSFWorkbook workbook, HSSFFont font)
 {
     SetCellStyleProperty(cell, workbook, FONT, font);
 }
示例#2
0
        /// <summary>
        /// Get the font at the given index number
        /// </summary>
        /// <param name="idx">The index number</param>
        /// <returns>HSSFFont at the index</returns>
        public LF.Utils.NPOI.SS.UserModel.IFont GetFontAt(short idx)
        {
            if (fonts == null) fonts = new Hashtable();

            // So we don't confuse users, give them back
            //  the same object every time, but create
            //  them lazily

            if (fonts.ContainsKey(idx))
            {
                return (HSSFFont)fonts[idx];
            }

            FontRecord font = workbook.GetFontRecordAt(idx);
            HSSFFont retval = new HSSFFont(idx, font);
            fonts[idx] = retval;

            return retval;
        }
示例#3
0
        /// <summary>
        /// Clones all the style information from another
        /// HSSFCellStyle, onto this one. This
        /// HSSFCellStyle will then have all the same
        /// properties as the source, but the two may
        /// be edited independently.
        /// Any stylings on this HSSFCellStyle will be lost!
        /// The source HSSFCellStyle could be from another
        /// HSSFWorkbook if you like. This allows you to
        /// copy styles from one HSSFWorkbook to another.
        /// </summary>
        /// <param name="source">The source.</param>
        public void CloneStyleFrom(HSSFCellStyle source)
        {
            // First we need to clone the extended format
            //  record
            format.CloneStyleFrom(source.format);

            // Handle matching things if we cross workbooks
            if (workbook != source.workbook)
            {
                // Then we need to clone the format string,
                //  and update the format record for this
                short fmt = (short)workbook.CreateFormat(
                        source.GetDataFormatString()
                );
                this.DataFormat=(fmt);

                // Finally we need to clone the font,
                //  and update the format record for this
                FontRecord fr = workbook.CreateNewFont();
                fr.CloneStyleFrom(
                        source.workbook.GetFontRecordAt(
                                source.FontIndex
                        )
                );

                HSSFFont font = new HSSFFont(
                        (short)workbook.GetFontIndex(fr), fr
                );
                this.SetFont(font);
            }
        }
示例#4
0
 /// <summary>
 /// Convert HSSFFont to Font.
 /// </summary>
 /// <param name="font1">The font.</param>
 /// <returns></returns>
 public System.Drawing.Font HSSFFont2Font(HSSFFont font1)
 {
     return new System.Drawing.Font(font1.FontName, font1.FontHeightInPoints);
 }