Hello,
When attempting to export a manually created workbook I obtain this error message:
Value cannot be null.
Parameter name: workbook at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Utilities.XlsxHelper.ConvertColumnPixelWidthToExcelWidth(Workbook workbook, Double columnWidthInPixels)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Contexts.XlsxWorksheetExportContext..ctor(XlsxWorkbookExportContext workbookContext, Worksheet worksheet, Int32 sheetNo)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Contexts.XlsxWorkbookExportContext.InitializeWorksheetContexts()
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Contexts.XlsxWorkbookExportContext.Initialize()
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider.ExportOverride(Workbook workbook, Stream output)
at [Redacted] Controller.cs:line 203
I Generate the workbook using this method:
public Workbook WriteExcelFile(List<Object> list)
{
Workbook workbook = new Workbook();
using (Worksheet worksheet = workbook.Worksheets.Add())
{
CellRange range = new CellRange(1, 1, list.Count, 5);
CellSelection selection = worksheet.Cells[range];
if (selection.CanInsertOrRemove(range, ShiftType.Right))
{
selection.Insert(InsertShiftType.Right);
}
for (int row = 0; row < list.Count; row++)
{
worksheet.Cells[row, 0].SetValue(list[row].string1);
worksheet.Cells[row, 1].SetValue(list[row].string2);
worksheet.Cells[row, 2].SetValue(list[row].string3);
worksheet.Cells[row, 3].SetValue(list[row].string4);
worksheet.Cells[row, 4].SetValue(list[row].string5);
}
}
return workbook;
}
The attempt to write it to a memory stream (FileStream was also attempted)
using (Stream output = new MemoryStream(10000))
formatProvider.Export(workbook, output);
Could you help me understand the reason behind this error?
I would like to be able to read a PDF document and import the contents of tables within the PDF document. Do you have an examples that shows how I would:
I'm just trying to create a table in PDF with this:
https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/table
In general a nice thing.
1) The only way to set the Font of the (entire) table I found, is to set the Font for each singular block in each singular cell, and this before inserting the text.
That means I cannot just do this: AddTableCell().Blocks.AddBlock().InsertText("cell11");
Is there a simpler way, to have some Default for the entire Table ? I found this DefaultCellProperties thing, but this concerns only background and borders
2) There is this property
table.LayoutType = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.TableLayoutType.FixedWidth;
The automatic works quiet well if you have text in the table, having f.e. an empty line, it shrinks the height of this line.
So I thought I changed to 'fixedwidth' and set it manually.
But than, I haven't found anything to set width oder height of Rows or Cells.
So what is this FixedWidth good for, how do I set the height of a Row or a ColumnWidth, although the concept of a column is kind of missing in this class.
Fails to open simple excel
var assembly = Assembly.GetEntryAssembly();
var resourceStream = assembly.GetManifestResourceStream("Dispatcher.Resources.someexcel.xlsx");
resourceStream.Position = 0;
XlsxFormatProvider formatProvider = new XlsxFormatProvider();
Workbook workbook = formatProvider.Import(resourceStream);
I cannot attach excel file here
stack trace
System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Worksheets.DataValidationElement.CopyPropertiesToSingleArgumentContext(SingleArgumentDataValidationRuleContext context)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Worksheets.DataValidationElement.CopyPropertiesToDataValidationRuleContext(DataValidationRuleContextBase context)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Worksheets.DataValidationElement.ListRuleFactory(IXlsxWorksheetImportContext context)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Worksheets.DataValidationElement.OnAfterRead(IXlsxWorksheetImportContext context)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Worksheets.WorksheetElementBase.OnAfterRead(IXlsxWorkbookImportContext context)
at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase`3.OnAfterRead(IOpenXmlImportContext context)
at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Parts.OpenXmlPartBase.Import(IOpenXmlReader reader, IOpenXmlImportContext context)
at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.ImportXlsxPartFromArchive(ZipArchiveEntry zipEntry, OpenXmlPartBase part, IOpenXmlImportContext context)
at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.Import(Stream input, IOpenXmlImportContext context)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider.ImportOverride(Stream input)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.WorkbookFormatProviderBase.Import(Stream input)
at Dispatcher.Controllers.ClientsController.<GenerateAccurals>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
Exception thrown: 'System.NullReferenceException' in Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.dll
Object reference not set to an instance of an object.
Hi
I coding below . I can convert file but document file inside textbox , these textbox can't convert to pdf file and document file inside picture alignment fix positing on page but can't convert to pdf file. I am using below code and I got empty page after convert pdf file. Because my doc file inside picture and textbox.
I try other document file include pic (in line with text ) and not include textbox. These file can get correct format with pdf file.
My Coding.....
Dim fileFormatProvider As IFormatProvider(Of Flow.Model.RadFlowDocument) = New Flow.FormatProviders.Docx.DocxFormatProvider()
Dim documentToConvert As Flow.Model.RadFlowDocument = New Flow.Model.RadFlowDocument()
Using input As FileStream = New FileStream("H:\\Files\\Testing.docx", FileMode.Open)
documentToConvert = fileFormatProvider.Import(input)
End Using
fileFormatProvider = New Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider()
Using output As Stream = New FileStream(pathpdf, FileMode.OpenOrCreate)
fileFormatProvider.Export(documentToConvert, output)
End Using
Thanks
Moe
var providerDocx =
new
DocxFormatProvider();
var document = providerDocx.Import(inStream);
//inStream is read from a docx file earlier
var providerPdf =
new
PdfFormatProvider();
Stream outStream =
new
MemoryStream();
providerPdf.Export(document, outStream);
//Test the conversion:
var fileStream = File.Create(
"PdfTest.pdf"
);
outStream.Seek(0, SeekOrigin.Begin);
outStream.CopyTo(fileStream);
fileStream.Close();
Hello, I had an application that used the excel interop, but I have changed it and now, to create the excels I use telerik, but some of my clients that use Excel 2003 have problems to open the excel created, they appear rare characters. Any ideas please? My code is something like that
string
nombre= ruta +
"\\excel.xls"
;
Workbook workbook =
new
Workbook();
workbook.Sheets.Add(SheetType.Worksheet);
Worksheet xlsSheet = xlsBook.ActiveWorksheet;
xlsSheet.Cells[1, 1].SetValue(
"prueba"
);
...
...
//Guardamos y abrimos la excel.
IWorkbookFormatProvider formatProvider = WorkbookFormatProvidersManager.GetProviderByName(
"XlsxFormatProvider"
);
using
(Stream output =
new
FileStream(nombre, FileMode.Create))
{
formatProvider.Export(workbook, output);
}
Thank you!
Good day,
I'm importing an Excel file and I need to validate all the cells an then import the result in our database.
When I have and error I change the Cell color. For small file I don't fell a performance issue. But on big file it's not possible. It take about half a second to change the color.
I turn off the History mode on the Woorkbook. wb.History.IsEnabled = false;
This is my code with cellSelection.SetFill(SolidErrorFill); commented to have better speed. How can I achieve a better speed ?
Thanks!
01.
public
override
IExcelRuleResult Evaluate(Worksheet ws)
02.
{
03.
var result =
new
ExcelRuleResult();
04.
result.ExcelIsValid =
true
;
05.
CellRange cr = ws.UsedCellRange;
06.
if
(cr !=
null
)
07.
{
08.
for
(
int
rowIndex = 1; rowIndex <= cr.ToIndex.RowIndex; rowIndex++)
09.
{
10.
// Read Row 0 for header name and validate if all the cells have the same format
11.
var sale =
new
Sale();
12.
for
(
int
columnIndex = cr.FromIndex.ColumnIndex; columnIndex <= cr.ToIndex.ColumnIndex; columnIndex++)
13.
{
14.
RangePropertyValue<ICellValue> rpv =
null
;
15.
CellSelection cellSelection =
null
;
16.
//var rpvName = ws.Cells[0, columnIndex].GetValue();
17.
var columnName = (layout.Layouts[columnIndex]
as
XlsxLayoutBase)?.ColumnName;
18.
var columnLayout = layout.Layouts[columnIndex]
as
XlsxLayoutBase;
19.
string
value =
null
;
20.
if
(columnLayout !=
null
)
21.
{
22.
try
23.
{
24.
25.
cellSelection = ws.Cells[rowIndex, columnIndex];
26.
rpv = cellSelection.GetValue();
27.
if
(rpv.Value
is
FormulaCellValue fcv)
28.
{
29.
value = fcv.GetResultValueAsString(
new
CellValueFormat(columnLayout.FormatString));
30.
}
31.
else
32.
{
33.
value = rpv.Value.RawValue;
34.
}
35.
36.
if
(columnLayout.DataType == EnumDataType.Date)
37.
{
38.
// Assembly: ServiceStack.Text .ToDoubleInvariant()
39.
value = FormatHelper.ConvertDoubleToDateTime(value.ToDoubleInvariant())?.Date.ToString(
"O"
);
40.
}
41.
42.
if
(columnLayout.Mandatory &&
string
.IsNullOrWhiteSpace(value))
43.
{
44.
//cellSelection.SetFill(SolidErrorFill);
45.
// We have {rowIndex+1} so it's the same line excel, 0 Base array in c# and Excel start at 1
46.
result.Messages.Add($
"Mandatory Value: ({value}) for ColumnName ({columnName}) at Row {rowIndex + 1}"
);
47.
result.ExcelIsValid =
false
;
48.
}
49.
else
50.
{
51.
//MapperHelper.AssignFieldValue(value, sale, columnName);
52.
}
53.
}
54.
catch
(Exception ex)
55.
{
56.
//cellSelection?.SetFill(SolidErrorFill);
57.
result.ExcelIsValid =
false
;
58.
// We have {rowIndex+1} so it's the same line excel, 0 Base array in c# and Excel start at 1
59.
result.Messages.Add($
"Exception Column Value: ({value}) for ColumnName ({columnName}) at Row {rowIndex + 1} {ex.Message}"
);
60.
}
61.
}
62.
}
63.
Sales.Add(sale);
64.
Console.WriteLine(rowIndex);
65.
}
66.
}
67.
return
result;
68.
}
HI,
I have an application which is generating a PDF report using FIxedContentEditor, some of the report must contain a dump of the contents of various RadPanel controls, my current implementation first creates a bitmap of the control using control.DrawToBitmap and then converts this to a BitmapSource and then an ImageSource.
Its not particularly fast and takes around 2.5 seconds for a single 3000x2000 full page image to be added to the PDF, is there a better / faster / more efficient way this can be achieved ?
Regards
Toby