Пример #1
0
        /// <summary><see cref="SheetData"/>に 文字を設定</summary>
        /// <param name="data"></param>
        /// <param name="rowIndex"></param>
        /// <param name="columnName"></param>
        /// <param name="text"></param>
        public static void SetText(this SheetData data, uint rowIndex, string columnName, string text, uint?styleIndex = null)
        {
            var worksheet = data.GetWorksheet();
            var bookPart  = worksheet.WorksheetPart.GetWorkbookPart();
            var tablePart = bookPart.GetSharedStringTablePart();

            var cell = data.GetCell(rowIndex, columnName);

            cell.DataType  = CellValues.SharedString;
            cell.CellValue = new CellValue(tablePart.GetIndex(text).ToString());
            if (styleIndex.HasValue)
            {
                cell.StyleIndex = styleIndex.Value;
            }
        }