예제 #1
0
        public void WorksheetMultipleStyleTest()
        {
            MemoryStream        stream        = SpreadsheetReader.Create();
            SpreadsheetDocument doc           = SpreadsheetDocument.Open(stream, true);
            WorksheetPart       worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1");

            SpreadsheetStyle style = SpreadsheetReader.GetDefaultStyle(doc);

            style.IsItalic = true;
            style.SetBackgroundColor("FF0000");//(red)

            WorksheetWriter.PasteText(doc, worksheetPart, "B", 2, "Hello world");
            WorksheetWriter.SetStyle(style, doc, worksheetPart, "B", 2);

            style        = SpreadsheetReader.GetDefaultStyle(doc);
            style.IsBold = true;
            style.SetBackgroundColor("0000FF");//(blue)

            WorksheetWriter.SetStyle(style, doc, worksheetPart, "C", 3);
            WorksheetWriter.PasteText(doc, worksheetPart, "C", 3, "Hello world2");

            //Save to the memory stream, and then to a file
            SpreadsheetWriter.Save(doc);
            SpreadsheetWriter.StreamToFile(string.Format("{0}\\styled2.xlsx", GetOutputFolder()), stream);
        }
예제 #2
0
        public void WorksheetAddStyleTest()
        {
            MemoryStream        stream        = SpreadsheetReader.Create();
            SpreadsheetDocument doc           = SpreadsheetDocument.Open(stream, true);
            WorksheetPart       worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1");

            SpreadsheetStyle defaultStyle = SpreadsheetReader.GetDefaultStyle(doc);

            defaultStyle.IsItalic    = true;
            defaultStyle.IsBold      = true;
            defaultStyle.IsUnderline = true;
            defaultStyle.SetColor("FF0000");
            //r = 255, g = 0, b = 0 (Red)
            defaultStyle.SetBackgroundColor("DDDDDD");
            //(light grey)
            defaultStyle.SetBorder("00FF00", BorderStyleValues.Medium);
            //(green medium border)

            WorksheetWriter.PasteText(doc, worksheetPart, "E", 5, "Hello world");
            WorksheetWriter.SetStyle(defaultStyle, doc, worksheetPart, "E", 5);

            //Save to the memory stream, and then to a file
            SpreadsheetWriter.Save(doc);
            SpreadsheetWriter.StreamToFile(string.Format("{0}\\styled.xlsx", GetOutputFolder()), stream);
        }
예제 #3
0
        public void WorksheetBorderTest()
        {
            MemoryStream        stream        = SpreadsheetReader.Create();
            SpreadsheetDocument doc           = SpreadsheetDocument.Open(stream, true);
            WorksheetPart       worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1");

            WorksheetWriter writer = new WorksheetWriter(doc, worksheetPart);

            //Fill a background cell to make sure it is not overwritten
            SpreadsheetStyle style = SpreadsheetReader.GetDefaultStyle(doc);

            style.SetBackgroundColor("C0C0C0");
            //(grey)
            writer.SetStyle(style, "B2");

            writer.DrawBorder("B2", "D4", "FF0000", BorderStyleValues.Medium);

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