예제 #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);
        }
예제 #2
0
        public void WorksheetAddAlignmentTest()
        {
            MemoryStream        stream        = SpreadsheetReader.Create();
            SpreadsheetDocument doc           = SpreadsheetDocument.Open(stream, true);
            WorksheetPart       worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1");
            SpreadsheetStyle    style         = SpreadsheetReader.GetDefaultStyle(doc);
            WorksheetWriter     writer        = new WorksheetWriter(doc, worksheetPart);

            style.IsWrapped = true;
            writer.PasteText("E5", "Wrapped text", style);

            style.IsWrapped = false;
            style.SetHorizontalAlignment(HorizontalAlignmentValues.Center);
            writer.PasteText("E7", "Aligned Test", style);

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