Use the code to import a sample txt file containing a "+" sign in a cell value:
Workbook workbook;
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.TextBased.Txt.TxtFormatProvider();
using (Stream input = new FileStream(@"sample.txt", FileMode.Open))
{
workbook = formatProvider.Import(input);
}
Expected behavior: the file is imported successfully
Actual behavior: an error is thrown
Hi Telerik,
I would like to request 1 feature to be added in Current RADGRID control which is to exporting grid data to into Excel 2016 version.
We need this feature because one of our supporting application will work only with Excel 2016 version, where as the current RADGRID conversion only able to export to EXCEL 2007 (excel 12) format.
Thank you.
NullReferenceException when the FindOptions does not contain start cell
Workaround:
Set StatCell like this:
FindOptions options = new FindOptions()When the worksheet contains fraction numbers with fractional parts > 0.5 and < 0.5 and both these numbers have fraction format applied, the number with fractional part < 0.5 will have incorrect whole part.
The row declaration is the following: <row r="8" spans="1:18" ht="15.75" x14ac:dyDescent="0.25"> The dyDescent attribute is described as follows: The dyDescent attribute is a double attribute, as specified in [XMLSCHEMA2/2] section 3.2.5, that specifies the vertical distance in pixels from the bottom of the cells in the current row to the typographical baseline of the cell content if, hypothetically, the zoom level for the sheet containing this row is 100 percent and the cell has bottom-alignment formatting. See section 2.2.4.12 for how this element integrates with the Office Open XML file formats specified in [ISO/IEC29500-1:2016]. The dyDescent attribute has a side effect; it sets the customHeight attribute to true even if the customHeight attribute is explicitly set to false. Note: Since the dyDescent attribute is not implemented, the height is not recognized to be custom and therefore it is not imported at all. The row has the default height.
Closed as duplicate. Please, follow the item at https://feedback.telerik.com/Project/184/Feedback/Details/190249 .
When the workbook contains multiple styles (e.g. 50000), the import is extremely slow. MS Excel loads this document instantaneously.
Most often, the print area will be defined in the Workbook part like so: <definedName name="_xlnm.Print_Area" localSheetId="3">Data!$A$1:$L$7</definedName> Sometimes, however, it can be a function instead: <definedName name="_xlnm.Print_Area" localSheetId="0">OFFSET('Parametrový List'!$A$1,0,0,INDEX({77,148},PocetStran),34)</definedName> At the moment, the second option is not supported.
When a format code like "General" x"" is applied on e.g. 1, the result is "1 x". At the moment, the result with Spreadprocessing is "General x"
When the automatic scaling options FitToColumns and FitToRows are used, the vertical and horizontal breaks, respectively, should be ignored. Workaround: Remove the page breaks if the worksheet uses automatic scaling and restore them if necessary: public void ExcelToPdf(string path) { var provider = new XlsxFormatProvider(); using (Stream input = File.OpenRead(path)) { var workbook = provider.Import(input); this.CachePageBreaks(workbook); var pdfProvider = new PdfFormatProvider(); pdfProvider.ExportSettings = new PdfExportSettings(ExportWhat.EntireWorkbook, false); using (Stream output = File.Open(@"C:\Users\velcheva\Desktop\26293903-c650-4d28-adee-58a542651f72_exceltopdf\exported.pdf", FileMode.Create)) { pdfProvider.Export(workbook, output); } this.RestorePageBreaks(workbook); } } private Dictionary<Worksheet,List<PageBreak>> verticalPageBreaksCache; private void CachePageBreaks(Workbook workbook) { this.verticalPageBreaksCache = new Dictionary<Worksheet, List<PageBreak>>(); foreach (Worksheet worksheet in workbook.Worksheets) { WorksheetPageSetup pageSetup = worksheet.WorksheetPageSetup; if (pageSetup.FitToPages) { this.verticalPageBreaksCache[worksheet] = new List<PageBreak>(pageSetup.PageBreaks.VerticalPageBreaks); if(pageSetup.FitToPagesWide != 0) { List<PageBreak> breaksToRemove = new List<PageBreak>(); breaksToRemove.AddRange(pageSetup.PageBreaks.VerticalPageBreaks); breaksToRemove.ForEach((br) => pageSetup.PageBreaks.TryRemoveVerticalPageBreak(0, br.Index)); } // Record the horizontal page breaks if necessary. } } } private void RestorePageBreaks(Workbook workbook) { foreach (Worksheet worksheet in workbook.Worksheets) { WorksheetPageSetup pageSetup = worksheet.WorksheetPageSetup; if (pageSetup.FitToPages) { List<PageBreak> cachedbreaks = this.verticalPageBreaksCache[worksheet]; if (pageSetup.FitToPagesWide != 0) { foreach (var pageBreak in cachedbreaks) { pageSetup.PageBreaks.TryInsertVerticalPageBreak(0, pageBreak.Index); } } // Restore the horizontal page breaks if necessary. } } }
Handle the case where the formula starts with "=+". Detailed information: https://professor-excel.com/equal-plus-excel-formulas/
Workaround: replace the "=+" with "="
CellRange usedCellRange = workbook.Worksheets[0].UsedCellRange;
for (int rowIndex = usedCellRange.FromIndex.RowIndex; rowIndex <= usedCellRange.ToIndex.RowIndex; rowIndex++)
{
for (int columnIndex = usedCellRange.FromIndex.ColumnIndex; columnIndex <= usedCellRange.ToIndex.ColumnIndex; columnIndex++)
{
CellSelection cell = workbook.Worksheets[0].Cells[rowIndex, columnIndex];
FormulaCellValue formulaCellValue =cell.GetValue().Value as FormulaCellValue;
if (formulaCellValue == null)
{
continue;
}
CellValueFormat format = cell.GetFormat().Value;
string resultValueAsString = formulaCellValue.GetValueAsString(format);
Console.WriteLine(resultValueAsString);
if (resultValueAsString.StartsWith("=+"))
{
resultValueAsString = resultValueAsString.Remove(1, 1);
cell.SetValue(resultValueAsString);
}
}
}
radSpreadsheet.Workbook = workbook;
Excel provides an option to choose whether cells with number cell value zero should display as "0" or as if they are empty. The option can be found in File -> Options -> Advanced -> "Show a zero in cells that have zero value". The option is set per sheet. The XML attribute is called "zeroValues" and it can be found on page 1625 in the format specification.