{"record":{"id":"4abd1015aebe61f9","repo":"QuestPDF/QuestPDF","slug":"prefix-a-cell-must-span-at-least-one-column-got","errorCode":null,"errorMessage":"{prefix} A cell must span at least one column. Got {cell.ColumnSpan}.","messagePattern":"(.+?) A cell must span at least one column\\. Got (.+?)\\.","errorType":"exception","errorClass":"DocumentComposeException","httpStatus":null,"severity":"error","filePath":"src/dotnet/library/QuestPDF/Elements/Table/TableLayoutValidator.cs","lineNumber":26,"sourceCode":"        public static void ValidateCellPositions(this Table table)\n        {\n            ValidateCellPositions(table.Columns.Count, table.Cells);\n        }\n        \n        private static void ValidateCellPositions(int columnsCount, ICollection<TableCell> cells)\n        {\n            const string prefix = \"Detected issue in table cells configuration.\";\n            \n            foreach (var cell in cells)\n            {\n                if (cell.Column < 1)\n                    throw new DocumentComposeException($\"{prefix} A cell column position should be greater or equal to 1. Got {cell.Column}.\");\n                \n                if (cell.Row < 1)\n                    throw new DocumentComposeException($\"{prefix} A cell row position should be greater or equal to 1. Got {cell.Row}.\");\n                \n                if (cell.ColumnSpan < 1)\n                    throw new DocumentComposeException($\"{prefix} A cell must span at least one column. Got {cell.ColumnSpan}.\");\n                \n                if (cell.RowSpan < 1)\n                    throw new DocumentComposeException($\"{prefix} A cell must span at least one row. Got {cell.RowSpan}.\");\n                \n                if (cell.Column > columnsCount)\n                    throw new DocumentComposeException($\"{prefix} Cell starts at column that does not exist. Cell details: {GetCellDetails(cell)}.\");\n                \n                if (cell.Column + cell.ColumnSpan - 1 > columnsCount)\n                    throw new DocumentComposeException($\"{prefix} Table cell location is incorrect. Cell spans over columns that do not exist. Cell details: {GetCellDetails(cell)}.\");\n            }\n\n            string GetCellDetails(TableCell cell)\n            {\n                return $\"Row {cell.Row}, Column {cell.Column}, RowSpan {cell.RowSpan}, ColumnSpan {cell.ColumnSpan}\";\n            }\n        }\n    }\n}","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/QuestPDF/QuestPDF/blob/43ab12559671556e10a6a0a5afe542c919f48a21/src/dotnet/library/QuestPDF/Elements/Table/TableLayoutValidator.cs#L8-L44","documentation":"ValidateCellPositions throws DocumentComposeException when a cell's ColumnSpan < 1 - a cell must cover at least one column. The offending ColumnSpan value is reported in the message with the standard configuration-issue prefix.","triggerScenarios":"Configuring a cell with .ColumnSpan(0), a negative span, or a computed span that resolves to <= 0.","commonSituations":"Computing ColumnSpan as (endCol - startCol) without adding 1; default(int) used as span; off-by-one in span math.","solutions":["Ensure ColumnSpan is at least 1 for every cell.","When computing span from start/end indices, use (end - start + 1).","Validate the computed span is >= 1 before configuring the cell."],"exampleFix":"// before:\ncell.Column(start).ColumnSpan(end - start); // 0 when start==end\n\n// after:\ncell.Column(start).ColumnSpan(end - start + 1);","handlingStrategy":"validation","validationCode":"if (cell.ColumnSpan < 1) throw new ArgumentException(\"ColumnSpan must be >= 1\", nameof(cell.ColumnSpan));","typeGuard":"static bool IsValidColumnSpan(int span) => span >= 1;","tryCatchPattern":null,"preventionTips":["Compute span as end - start + 1.","Validate computed spans are >= 1."],"tags":["table","validation","compose"],"backgroundTag":null,"analyzedSha":"43ab12559671556e10a6a0a5afe542c919f48a21","analyzedAt":"2026-08-13T17:02:41.303Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}