Exemple #1
0
        public virtual void WriteRows <T>(StreamWriter writer, IEnumerable <T> items, ExcelColumn <T>[] columns)
        {
            var row  = 2;
            var cols = columns.Length;

            foreach (var item in items)
            {
                writer.Write("<row r=\"{0}\" >", row);

                for (var colNumber = 1; colNumber <= cols; colNumber++)
                {
                    var column = columns[colNumber - 1];
                    var value  = column.DataProvider(item);

                    writer.Write("<c r=\"");
                    writer.Write(GetColumnName(colNumber));
                    writer.Write(row);
                    writer.Write("\"");

                    if (column.Style != null)
                    {
                        writer.Write(" s=\"");
                        writer.Write(column.Style.Value);
                        writer.Write("\"");
                    }

                    writer.Write(" t=\"");
                    writer.Write(column.ExcelDataType);
                    writer.Write("\">");


                    if (column.ExcelDataType == ExcelDataTypes.InlineString)
                    {
                        value = _xmlEncoder.Encode(value);

                        writer.Write("<is><t>");
                        writer.Write(value);
                        writer.Write("</t></is>");
                    }
                    else
                    {
                        if (column.ExcelDataType == ExcelDataTypes.String)
                        {
                            value = _interner.Intern(value).ToString();
                        }

                        writer.Write("<v>");
                        writer.Write(value);
                        writer.Write("</v>");
                    }

                    writer.Write("</c>");
                }

                writer.Write("</row>");
                row++;
            }
        }
Exemple #2
0
 private void WriteContent(StreamWriter writer, Dictionary <string, int> cache)
 {
     // order of items in dictionary may be different from insert order
     foreach (var item in cache.OrderBy(x => x.Value))
     {
         writer.Write("<si><t>");
         writer.Write(_xmlEncoder.Encode(item.Key));
         writer.Write("</t></si>");
     }
 }