zoukankan      html  css  js  c++  java
  • Open Xml 写入日期类型

     效果图:

      

    关键代码:

    类型判断

                            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也需要写入。

  • 相关阅读:
    老人与小孩
    搭讪
    VIM 如何使用系统的剪切板
    Linux 下如何安装 .rpm 文件
    Linux 下如何安装 .bin 文件
    Tomorrow Is A New Day
    Hive 学习(五) Hive之HSQL基础
    Hive 学习(二) hive安装
    Hive 学习(四) Hive的数据类型
    Hive 学习(三) Hive的DDL操作
  • 原文地址:https://www.cnblogs.com/sshoub/p/2661648.html
Copyright © 2011-2022 走看看