daixinet

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 效果图:

  

 

关键代码:

类型判断

                        if (rIndex == 1)
                        {
                            cell.CellValue = new CellValue(item.ToString());
                        }
                        else if (rIndex == 2)
                        {
                            cell.CellValue = new CellValue(((DateTime)item).ToOADate().ToString());
                            cell.StyleIndex = 1;
                        }
                        else
                        {
                            int index = InsertSharedStringItem(item.ToString(), m_SharedStringTablePart);
                            cell.CellValue = new CellValue(index.ToString());
                            cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
                        }


Style:

        static Stylesheet CreateStylesheet()
        {
            Stylesheet stylesheet1 = new Stylesheet();

            Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U, KnownFonts = true };
            Font font1 = new Font();
            fonts1.Append(font1);
            Fills fills1 = new Fills() { Count = (UInt32Value)1U };
            Fill fill1 = new Fill();
            fills1.Append(fill1);
            Borders borders1 = new Borders() { Count = (UInt32Value)1U };
            Border border1 = new Border();
            borders1.Append(border1);

            CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)2U };
            CellFormat cellFormat1 = new CellFormat() ;
            CellFormat cellFormat2 = new CellFormat()
            { 
                NumberFormatId = (UInt32Value)22U, 
                ApplyNumberFormat = true 
            };
            cellFormats1.Append(cellFormat1);
            cellFormats1.Append(cellFormat2);

            stylesheet1.Append(fonts1);
            stylesheet1.Append(fills1);
            stylesheet1.Append(borders1);
            stylesheet1.Append(cellFormats1);

            return stylesheet1;
        } 

其中,fonts,fills和borders需要写入,这个很关键,并且cellFormat1也需要写入。

 

posted on 2012-08-29 10:54  daixinet.com  阅读(784)  评论(0编辑  收藏  举报