Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
925
Change Excel template style after loading to Spreadsheet control
posted

Hi,

I am loading the Excel template file which contains formatted table with headers with size of 14. Viewing the same data in the XamSpreadsheet control results in oversized font in multiple worksheets.

As a workaround we tried to apply default normal styles and override this for each workbook manually:

public Workbook ApplyTo(Workbook workbook)
{
     ApplyTo(workbook.Styles.NormalStyle);
     ApplyTo(workbook.Worksheets);
}

private void ApplyTo(WorkbookStyle style) => ApplyTo(style.StyleFormat.Font);

private void ApplyTo(IWorkbookFont font)
{
			font.Name = mFontName;
			font.Height = mFontHeightTwips;
}

private void ApplyTo(WorksheetCollection sheets)
{
			foreach (var sheet in sheets)
			{
				sheet.DefaultRowHeight = mFontHeightTwips + FONT_HEIGHT_TO_ROW_HEIGHT_OFFSET;

				if (sheet.Rows.Any())
					sheet.Rows[0].CellFormat.Font.Height = mFontHeightTwips;
			}
}

However, this has a side affect which results in applying all possible worksheet columns as result manual processing of all data takes ages to process since unused columns becoming as changed and resulting in column count of 16384 when querying number: 

var columnCount = mWorksheet.UsedRange.Columns.Count

How to fix the problem with applying change to real cells or use different approach to change style to reduce Font size from 14 to smaller number?

Example of oversized text in cells: