Exemplo n.º 1
0
        public void WhenCloneCell_ThenCellIsCloned()
        {
            string outputPath = Path.ChangeExtension(Path.Combine("TestData", MethodBase.GetCurrentMethod().Name), ".xlsx");

            byte[] templateData = File.ReadAllBytes(@"TestData\StudentProfileExportTemplate.xltx");
            using (MemoryStream stream = new MemoryStream())
            {
                stream.Write(templateData, 0, (int)templateData.Length);
                using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
                {
                    spreadsheetDoc.ChangeDocumentType(SpreadsheetDocumentType.Workbook);
                    Worksheet worksheet = spreadsheetDoc.WorkbookPart.WorksheetParts.First().Worksheet;

                    ExcelUtility.CopyCell(worksheet, "D", 2, "E", 2);
                }
                File.WriteAllBytes(outputPath, stream.ToArray());
            }

            using (XLWorkbook workbook = new XLWorkbook(outputPath))
            {
                IXLWorksheet worksheet    = workbook.Worksheet(1);
                IXLCell      originalCell = worksheet.Cell(2, "D");
                IXLCell      clonedCell   = worksheet.Cell(2, "E");
                Assert.AreEqual(originalCell.DataType, clonedCell.DataType);
                Assert.AreEqual(originalCell.FormulaA1, clonedCell.FormulaA1);
                Assert.AreEqual(originalCell.FormulaR1C1, clonedCell.FormulaR1C1);
                Assert.AreEqual(originalCell.RichText.Text, clonedCell.RichText.Text);
                Assert.AreEqual(originalCell.ShareString, clonedCell.ShareString);
                Assert.AreEqual(originalCell.Style, clonedCell.Style);
                Assert.AreEqual(originalCell.Value, clonedCell.Value);
                Assert.AreEqual(originalCell.ValueCached, clonedCell.ValueCached);
            }
        }
Exemplo n.º 2
0
        private void WriteColumnHeading(uint columnIndex, string headerName)
        {
            string columnName = ExcelUtility.GetColumnNameFromIndex(columnIndex);

            ExcelUtility.EnsureColumn(Worksheet, columnIndex);
            if (columnIndex > 1)
            {
                ExcelUtility.CopyCell(Worksheet, "A", HeaderRowIndex, columnName, HeaderRowIndex);
            }
            ExcelUtility.SetSharedStringCell(Document, Worksheet, columnName, HeaderRowIndex, headerName);
        }