public static byte[] SerializeAndCompress(T obj)
{
var filename = DateTime.Now.ToString("ddMMYYYYhhmmss") + ".xml";
var appStore = IsolatedStorageFile.GetUserStoreForApplication();
if (appStore.Quota < TamanhoStorage) appStore.IncreaseQuotaTo(TamanhoStorage);
byte[] bobj;
using (var fileStream = appStore.OpenFile(filename, FileMode.Create))
{
var serializer = new DataContractSerializer(typeof(T));
serializer.WriteObject(fileStream, obj);
fileStream.Position = 0;
bobj = new byte[fileStream.Length];
fileStream.Read(bobj, 0, (int)fileStream.Length);
}
using (var fileStream = appStore.OpenFile(filename, FileMode.Create))
{
using (var zip = new ZipOutputStream(fileStream))
{
zip.Write(bobj, 0, bobj.Length);
}
}
byte[] cobj = null;
using (var fileStream = appStore.OpenFile(filename, FileMode.Open))
{
cobj = new byte[fileStream.Length];
fileStream.Read(cobj, 0, cobj.Length);
}
appStore.DeleteFile(filename);
return cobj;
}
using (var fileStream = appStore.OpenFile(filename, FileMode.Open))
{
using (var zip = new ZipInputStream(fileStream))
{
using (var sr = new StreamReader(zip))
{
var str = sr.ReadToEnd();
}
}
}
var bobj = new byte[5000000];
using (var fileStream = appStore.OpenFile(filename, FileMode.Open))
{
using (var zip = new ZipInputStream(fileStream))
{
zip.Read(bobj, 0, (int)fileStream.Length);
}
}
Hi,
I have Performance Issues with the Excel spreadprocessing export. I just migrated an Excel export that used until now the libraries "Component One". The export takes now 30 seconds for 7221 rows and 88 columns, against 5 seconds before. Here is the code:
001.
... Fill the table...
002.
Using excBook
As
New
Workbook
003.
004.
excBook.SuspendLayoutUpdate()
005.
Using (
New
UpdateScope(
006.
Function
() (excBook.History.IsEnabled =
False
),
007.
Function
() (excBook.History.IsEnabled =
True
)))
008.
009.
Dim
excSheet
As
Worksheet
010.
excSheet = excBook.Worksheets.Add()
011.
excSheet.Name = tbl.TableName
012.
fill_ExcelSheet(tbl, excSheet)
013.
014.
End
Using
015.
excBook.ResumeLayoutUpdate()
016.
017.
'Save the Excel-File
018.
Dim
formatProvider
As
Telerik.Windows.Documents.Spreadsheet.FormatProviders.IWorkbookFormatProvider _
019.
=
New
Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider()
020.
021.
Using fsOutput
As
New
FileStream(strFilename, FileMode.Create)
022.
formatProvider.Export(excBook, fsOutput)
023.
End
Using
024.
025.
End
Using
026.
027.
Private
Shared
Function
fill_ExcelSheet(
ByVal
tblDaten
As
DataTable,
ByVal
excSheet
As
Worksheet)
As
Boolean
028.
Dim
bolOK
As
Boolean
=
False
029.
Dim
intCntCols
As
Integer
, intCntRows
As
Integer
030.
Dim
strColCaption
As
String
031.
032.
Try
033.
034.
'Set Columns-Description
035.
For
intCntCols = 0
To
tblDaten.Columns.Count - 1
036.
strColCaption = get_AttributCaption(tblDaten.Prefix, tblDaten.Columns(intCntCols).ColumnName)
037.
excSheet.Cells.Item(0, intCntCols).SetValue(strColCaption)
038.
Next
039.
040.
'Fill the Sheet with data
041.
excSheet.Cells.Item(1, 0, tblDaten.Rows.Count, tblDaten.Columns.Count).SetFormat(
New
CellValueFormat(
"@"
))
042.
For
intCntRows = 0
To
tblDaten.Rows.Count - 1
043.
For
intCntCols = 0
To
tblDaten.Columns.Count - 1
044.
Dim
colName
As
String
= tblDaten.Columns(intCntCols).ColumnName
045.
If
(tblDaten.Columns(colName).DataType
Is
GetType
(
Date
))
Then
046.
If
Not
tblDaten.Rows(intCntRows).IsNull(colName)
Then
047.
If
CType
(tblDaten.Rows(intCntRows).Item(colName),
Date
).TimeOfDay.Ticks > 0
Then
048.
excSheet.Cells.Item(intCntRows + 1, intCntCols).SetValue(
CType
(tblDaten.Rows(intCntRows).Item(colName),
Date
).ToString)
049.
Else
050.
excSheet.Cells.Item(intCntRows + 1, intCntCols).SetValue(
CType
(tblDaten.Rows(intCntRows).Item(colName),
Date
).ToShortDateString)
051.
End
If
052.
End
If
053.
ElseIf
(tblDaten.Columns(colName).DataType
Is
GetType
(System.Guid))
Then
054.
excSheet.Cells.Item(intCntRows + 1, intCntCols).SetValue(tblDaten.Rows(intCntRows).Item(colName).ToString)
055.
ElseIf
(tblDaten.Columns(colName).DataType
Is
GetType
(
String
))
Then
056.
057.
excSheet.Cells.Item(intCntRows + 1, intCntCols).SetValue(tblDaten.Rows(intCntRows).Item(colName).ToString)
058.
ElseIf
(tblDaten.Columns(colName).DataType
Is
GetType
(
Integer
)) _
059.
Or
(tblDaten.Columns(colName).DataType
Is
GetType
(Int16)) _
060.
Or
(tblDaten.Columns(colName).DataType
Is
GetType
(
Single
)) _
061.
Or
(tblDaten.Columns(colName).DataType
Is
GetType
(
Decimal
)) _
062.
Or
(tblDaten.Columns(colName).DataType
Is
GetType
(
Double
))
Then
063.
If
Not
tblDaten.Rows(intCntRows).IsNull(colName)
Then
064.
excSheet.Cells.Item(intCntRows + 1, intCntCols).SetValue(
CDbl
(tblDaten.Rows(intCntRows).Item(colName)))
065.
End
If
066.
ElseIf
(tblDaten.Columns(colName).DataType
Is
GetType
(
Boolean
))
Then
067.
If
Not
tblDaten.Rows(intCntRows).IsNull(colName)
Then
068.
excSheet.Cells.Item(intCntRows + 1, intCntCols).SetValue(
CBool
(tblDaten.Rows(intCntRows).Item(colName)))
069.
End
If
070.
Else
071.
If
Not
tblDaten.Rows(intCntRows).IsNull(colName)
Then
072.
excSheet.Cells.Item(intCntRows + 1, intCntCols).SetValue(tblDaten.Rows(intCntRows).Item(colName))
073.
End
If
074.
End
If
075.
Next
076.
Application.DoEvents()
077.
Next
078.
079.
'Print properties
080.
Dim
pageSetup
As
Printing.WorksheetPageSetup = excSheet.WorksheetPageSetup
081.
pageSetup.PaperType = Telerik.Windows.Documents.Model.PaperTypes.A4
082.
pageSetup.PageOrientation = Telerik.Windows.Documents.Model.PageOrientation.Landscape
083.
Dim
HeadFootSettings
As
Printing.HeaderFooterSettings = pageSetup.HeaderFooterSettings
084.
HeadFootSettings.Header.CenterSection.Text = excSheet.Name
085.
HeadFootSettings.Footer.CenterSection.Text = DateTime.Now.ToString
086.
087.
If
excSheet.Workbook.Styles(
"NormalStyle"
)
Is
Nothing
Then
088.
Dim
normalStyleCells
As
Telerik.Windows.Documents.Spreadsheet.PropertySystem.CellStyle = excSheet.Workbook.Styles.Add(
"NormalStyle"
)
089.
Dim
borderDotCell
As
New
CellBorder(CellBorderStyle.Hair,
New
ThemableColor(ThemeColorType.Text1))
090.
Dim
borderThinCell
As
New
CellBorder(CellBorderStyle.Thin,
New
ThemableColor(ThemeColorType.Text1))
091.
Dim
fill
As
IFill = PatternFill.CreateSolidFill(
New
ThemableColor(Windows.Media.Colors.White))
092.
normalStyleCells.BeginUpdate()
093.
normalStyleCells.TopBorder = borderDotCell
094.
normalStyleCells.BottomBorder = borderDotCell
095.
normalStyleCells.LeftBorder = borderThinCell
096.
normalStyleCells.RightBorder = borderThinCell
097.
normalStyleCells.FontFamily =
New
ThemableFontFamily(
"Arial"
)
098.
normalStyleCells.FontSize = UnitHelper.PointToDip(8)
099.
normalStyleCells.Fill = fill
100.
normalStyleCells.EndUpdate()
101.
102.
Dim
headerStyleCells
As
Telerik.Windows.Documents.Spreadsheet.PropertySystem.CellStyle = excSheet.Workbook.Styles.Add(
"HeaderStyle"
)
103.
fill = PatternFill.CreateSolidFill(
New
ThemableColor(Windows.Media.Color.FromRgb(192, 192, 192)))
104.
headerStyleCells.CopyPropertiesFrom(normalStyleCells)
105.
headerStyleCells.BeginUpdate()
106.
headerStyleCells.IsWrapped =
False
107.
headerStyleCells.TopBorder = borderThinCell
108.
headerStyleCells.BottomBorder = borderThinCell
109.
headerStyleCells.Fill = fill
110.
headerStyleCells.EndUpdate()
111.
112.
Dim
footStyleCells
As
Telerik.Windows.Documents.Spreadsheet.PropertySystem.CellStyle = excSheet.Workbook.Styles.Add(
"FooterStyle"
)
113.
footStyleCells.CopyPropertiesFrom(normalStyleCells)
114.
footStyleCells.BottomBorder = borderThinCell
115.
116.
Dim
leftAlignStyleCells
As
Telerik.Windows.Documents.Spreadsheet.PropertySystem.CellStyle = excSheet.Workbook.Styles.Add(
"LeftAlignStyle"
)
117.
leftAlignStyleCells.HorizontalAlignment = RadHorizontalAlignment.Left
118.
Dim
rightAlignStyleCells
As
Telerik.Windows.Documents.Spreadsheet.PropertySystem.CellStyle = excSheet.Workbook.Styles.Add(
"RightAlignStyle"
)
119.
rightAlignStyleCells.HorizontalAlignment = RadHorizontalAlignment.Right
120.
End
If
121.
122.
excSheet.Columns(0, tblDaten.Columns.Count - 1).AutoFitWidth()
123.
Dim
rowHeight
As
New
RowHeight(UnitHelper.PointToDip(11.5),
True
)
124.
excSheet.Rows(0, tblDaten.Rows.Count).SetHeight(rowHeight)
125.
126.
'Format cells
127.
For
col
As
Integer
= 0
To
tblDaten.Columns.Count - 1
128.
'Links- oder Rechtsbündig setzen
129.
Dim
strAHorz
As
String
=
"LeftAlignStyle"
130.
Dim
typCol
As
Type = tblDaten.Columns(col).DataType
131.
If
(typCol
Is
GetType
(
Integer
))
Or
(typCol
Is
GetType
(
Single
))
Or
(typCol
Is
GetType
(
Decimal
))
Or
(typCol
Is
GetType
(
Double
))
Then
132.
strAHorz =
"RightAlignStyle"
133.
End
If
134.
135.
excSheet.Cells(0, col).SetStyleName(
"HeaderStyle"
)
136.
excSheet.Cells(1, col, tblDaten.Rows.Count - 1, col).SetStyleName(
"NormalStyle"
)
137.
excSheet.Cells(tblDaten.Rows.Count, col).SetStyleName(
"FooterStyle"
)
138.
139.
excSheet.Cells(0, col, tblDaten.Rows.Count, col).SetStyleName(strAHorz)
140.
Next
141.
bolOK =
True
142.
Catch
ex
As
Exception
143.
show_AppErrorMsgBox(ex)
144.
End
Try
145.
Return
bolOK
146.
End
Function
The code that takes the most time is:
- Lines 42 - 77: Fill the sheet with data: 12 seconds
- Line 122: AutoFitWidth(): 6 seconds --> (It's important, cannot be removed)
- Line 22: formatProvider.Export(excBook, fsOutput): 11 seconds --> That's very long !!!
Can you check my code and tell me if there are any improvements, please? So i can unfortunately not use the libraries.
Thanks in advance
Given a set of strings, how should I compute a pattern from it? For example, (see picture), would provide me "Cadastro de Pessoas FÃsicas de Inscrição Nome Nasc". Of course, I could do it manually by analyzing the strings, but I need an automatic procedure for it because they would be more complex. Any ideas? I realize that this issue has do more with algorythms that Telerik products themselves.
Hallo,
when i read the result of a cell with a formular how has a function (like SUM()) or a referenz (sheetname!Range) linked to a worksheet (itself or another) in the workbook the result (.GetResultValueAsString ) ist "0" or a text (the formular itself) and not the result. Simple formulars related to cells in the worksheet are ok.
Example:
The cell formular looks like this:
1. =SUMME(L23:L30) ==> GetResultValueAsString result = "0"
2. {=WENNFEHLER(INDEX(Bestellliste!E:E;KKLEINSTE(WENN(Bestellliste!$A$1:$A$1131="x";ZEILE($1:$991));ZEILE(A3)));"")} ==> GetResultValueAsString result = "=WENNFEHLER(INDEX(Bestellliste!E:E;KKLEINSTE(WENN(Bestellliste!$A$1:$A$1131="x";ZEILE($1:$991));ZEILE(A3)));"")"
VB code:
Dim iCellValue As ICellValue
iCellValue = TryCast(workbook.ActiveWorksheet.Cells(row, col).GetValue().Value, ICellValue)
If iCellValue IsNot Nothing Then
Dim format As CellValueFormat = workbook.ActiveWorksheet.Cells(row, col).GetFormat().Value
Dim valueAsString As String = iCellValue.GetValueAsString(format)
'valueAsString
Dim resultValueAsString As String = iCellValue.GetResultValueAsString(format)
'resultAsString
Dim valueType As CellValueType = iCellValue.ValueType
'valueType = Formula ' ==> allways Text{4} with komplex formular
'resultValueType = Number
Dim resultValueType As CellValueType = iCellValue.ResultValueType
End If
DLL Version: 2015.2.728.40
What's wrong? Are their any restriction to resolve formulars?
Regards
Harald
I'm trying to zip a PDF file, it creates zip file correctly, but if I try to open compressed PDF file, it show me error message "Corrupted file" (I'm trying to open by my PDF reader), where I wrong?
using
(Stream stream = File.Open(fileFullName, FileMode.Create))
{
using
(ZipArchive archive =
new
ZipArchive(stream, ZipArchiveMode.Create,
false
,
null
))
{
using
(ZipArchiveEntry entry = archive.CreateEntry(fi.Name))
{
var writer =
new
StreamWriter(entry.Open());
using
(Stream streamFileToZip = File.Open(fi.FullName, FileMode.Open))
{
var buffer =
new
byte
[4096];
int
sourceBytes = 0;
do
{
sourceBytes = streamFileToZip.Read(buffer, 0, buffer.Length);
writer.Write(buffer);
}
while
(sourceBytes > 0);
}
writer.Flush();
}
}
}
Hi !
I searching another way to generate my PDF document by WordsProcessing.
Compositing it and convert to PDF
After install by Configure project (CfgProject.png) the Document.Flow (RadWordsProcessing) when i want convert it like this sample :
the namespace "Telerik.Windows.Documents.Flow.FormatProviders.Pdf" is not found
The dll wasn't copied by Configure project ?! (FormatProvidersPdf.png)
it's a bug ? why ?
Thanks.
Hello,
Iam creating a pdf document wherein iam trying to set the size of the RadFixedPage object but the size property is showing as
page.Size=new System.Windows.Size()
instead of page.Size = new Size();
What am i missing ? Any reference?
I have already included the below references on my aspx page
using System.Windows;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export;
using Telerik.Windows.Documents.Fixed.Model;
using Telerik.Windows.Documents.Fixed.Model.ColorSpaces;
using Telerik.Windows.Documents.Fixed.Model.Editing;
using Telerik.Windows.Documents.Fixed.Model.Editing.Flow;
using Telerik.Windows.Documents.Fixed.Model.Fonts;
using Telerik.Windows.Documents.Fixed.Model.Graphics;
Thanks in Advance
Sushanth.B
Hi from France ! (and excuse me for my bad english)
After 3 days on RadFixedDocument to make a PDF file, i need help !
I must make a PDF File based on my Asp.net Vb.net website (attached file)
i must make a document with "same" design : Landscape document and grids on left and on right
Dim
document
As
New
Telerik.Windows.Documents.Fixed.Model.RadFixedDocument
document.DocumentInfo.Author =
"(c) Francelot"
document.DocumentInfo.Title =
"Bilan Gestion"
Dim
ex
As
New
Telerik.Windows.Documents.Fixed.Model.Editing.RadFixedDocumentEditor(document)
ex.SectionProperties.PageRotation = Telerik.Windows.Documents.Fixed.Model.Data.Rotation.Rotate90
ex.InsertSectionBreak()
ex.InsertRun(
"TEST"
)
ex.InsertLine(
"Bilan Gestion"
)
ex.Dispose()
After this i got landscape document but my text is right to left (write not landscape, just rotate page ...)
Thank for your help !
Vincent.
I'm currently using Telerik.Windows.Zip 2016.2.606.40.
Are there any file size limits, either to individual files in a ZIP or to the ZIP as a whole?
I'm getting an exception "Relative offset of the Central Directory Start is too big" while trying to process a large (~3GB) stream.
Thanks.
Hi,
Is it possible to export Arabic characters using Telerik Document Processing libraries ??