Exemplo n.º 1
0
        public void WorksheetSetStylesTest()
        {
            List <string> values  = new List <string>(new string[] { "alpha", "beta", "charlie", "delta" });
            List <string> values2 = new List <string>(new string[] { "echo", "foxtrot", "golf", "hotel" });

            //Write to the spreadsheet
            MemoryStream        stream        = SpreadsheetReader.Create();
            SpreadsheetDocument doc           = SpreadsheetDocument.Open(stream, true);
            WorksheetPart       worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1");
            WorksheetWriter     writer        = new WorksheetWriter(doc, worksheetPart);

            writer.PasteValues("A2", values, CellValues.String);
            writer.PasteValues("A3", values2, CellValues.String);

            //The centre four styles should be aligned to center
            SpreadsheetStyle style = SpreadsheetReader.GetDefaultStyle(doc);

            style.SetHorizontalAlignment(HorizontalAlignmentValues.Center);
            writer.SetStyle(style, "B2", "C3");

            //Set style in non existing cells
            writer.SetStyle(style, "B5", "C6");

            //Save to the memory stream, and then to a file
            SpreadsheetWriter.Save(doc);
            SpreadsheetWriter.StreamToFile(string.Format("{0}\\stylerange.xlsx", GetOutputFolder()), stream);
        }
Exemplo n.º 2
0
        public void WriteRow(string column, int row, List <string> values, SpreadsheetStyle style = null)
        {
            var startCell = column + row;

            _writer.PasteValues(startCell, values, CellValues.String);

            if (style != null)
            {
                var endCell = SpreadsheetReader.GetColumnName(column, values.Count - 1) + row;
                _writer.SetStyle(style, startCell, endCell);
            }
        }
Exemplo n.º 3
0
        public void WorksheetPasteValuesTest()
        {
            List <string> values = new List <string>(new string[] { "alpha", "beta", "charlie", "delta" });

            //Write to the spreadsheet
            MemoryStream        stream        = SpreadsheetReader.Create();
            SpreadsheetDocument doc           = SpreadsheetDocument.Open(stream, true);
            WorksheetPart       worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1");

            WorksheetWriter.PasteValues(doc, worksheetPart, "A", 2, values, CellValues.String, null);

            //Save to the memory stream, and then to a file
            SpreadsheetWriter.Save(doc);
            SpreadsheetWriter.StreamToFile(string.Format("{0}\\pastevalues.xlsx", GetOutputFolder()), stream);
        }