![]() ![]() IEnumerable rows = worksheet.Descendants().Where(r => r.RowIndex.Value = rowIndex) String columnName = GetColumnName(cellName) Private static Cell CreateSpreadsheetCellIfNotExist(Worksheet worksheet, string cellName) If it does not exist, creates a new cell. Given a Worksheet and a cell name, verifies that the specified cell exists. Private static Column CreateColumnData(UInt32 StartColumnIndex, UInt32 EndColumnIndex, double ColumnWidth) Width = (double)decimal.Round((decimal)width + 0.2M, 2) Size textSize = TextRenderer.MeasureText(text, stringFont) ĭouble width = (double)(((textSize.Width / (double)7) * 256) - (128 / 7)) / 256 This formula is based on this article plus a nudge ( + 0.2M ) Private static double GetWidth( stringFont, string text) Private static double GetWidth(string font, int fontSize, string text) Id = (worksheetPart),Ĭell = CreateSpreadsheetCellIfNotExist(worksheetPart.Worksheet, "B2") Ĭell = CreateSpreadsheetCellIfNotExist(worksheetPart.Worksheet, "C2") ĬellValue cellValue = new CellValue(count.ToString()) Append a new worksheet and associate it with the workbook. String strText = "This is some really, really long text to display." ĭouble width = GetWidth("Calibri", 11, strText) ĭouble width2 = GetWidth("Calibri", 11, strText2) Ĭolumns.Append(CreateColumnData(2, 2, width)) Ĭolumns.Append(CreateColumnData(3, 3, width2)) WorksheetPart.Worksheet = new Worksheet() WorksheetPart worksheetPart = workbookpart.AddNewPart() Add a WorksheetPart to the WorkbookPart. WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart() Using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(docName, SpreadsheetDocumentType.Workbook)) String docName = Create a Wordprocessing document. #EXCEL ADJUST COLUMN WIDTH TO FIT TEXT HOW TO#Haven't quite figured out how to do search yet. ![]() I should mention that I am NOT searching for the largest string in the column but rather calculating 1 item. #EXCEL ADJUST COLUMN WIDTH TO FIT TEXT CODE#Here is the complete source code to do it. The width based on the pixel width of the string. After poking around I found a formula which I rework to calculate I mostly found that the current spec doesn't support it automatically. I was trying to find a way to size the column to my largest item. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |