This is a migrated thread and some comments may be shown as answers.

Spread export events

16 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
VLADISLAV
Top achievements
Rank 1
VLADISLAV asked on 23 Nov 2015, 08:38 AM

using CellFormatting event.How can  i setup borders for cells .
            BorderStyles border = new BorderStyles();
            border.Color = Color.Black;
            border.Weight = 1;
            border.LineStyle = LineStyle.Continuous;
            border.PositionType = PositionType.Bottom;
How can i use this, cause somethng like that :
            e.CellStyleInfo.Borders = border;

doesn't work.

In exportML were e.ExcelStyleElement.Borders.Add function, cant find how this must work.

16 Answers, 1 is accepted

Sort by
0
VLADISLAV
Top achievements
Rank 1
answered on 23 Nov 2015, 08:57 AM
Also nim trying to addheader to created workbook and i can t fo\ind any info about workbook created event, eny request from
http://www.telerik.com/help/winforms/radgridview-exporting-data-how-to-add-header-and-footer.html or from search cause error.
0
VLADISLAV
Top achievements
Rank 1
answered on 23 Nov 2015, 08:58 AM
Also im trying to add header to created workbook and i cant find any info about workbook created event, any request from
http://www.telerik.com/help/winforms/radgridview-exporting-data-how-to-add-header-and-footer.html or from search cause error.***
0
Stefan
Telerik team
answered on 23 Nov 2015, 09:20 AM
Hello Vladislav,

Thank you for writing.

To set the borders, you need to create an object of type CellBorders and assign it to the CellStyleInfo.Borders property. Note that the ExportVisualStyles property of the GridViewSpreadExport should be set to  true.

Alternatively, you can use the SpreadProcessing API and work with the workbook.

In regards to inserting rows, again you can utilize the SpreadProcessing API. In this case, you can use the Workbook created event of the renderer, to get the workbook once it is cooked. From there you can perform any manipulations you need.

Here is an example:
private void radButton1_Click(object sender, EventArgs e)
{
    GridViewSpreadExport exporter = new GridViewSpreadExport(radGridView1);
    exporter.CellFormatting += exporter_CellFormatting;
    exporter.ExportVisualSettings = true;
 
    SpreadExportRenderer renderer = new SpreadExportRenderer();
    renderer.WorkbookCreated += renderer_WorkbookCreated;
    exporter.RunExport(@"D:\asd.xlsx", renderer);
}
 
void renderer_WorkbookCreated(object sender, WorkbookCreatedEventArgs e)
{
    Worksheet sheet = (Worksheet)e.Workbook.ActiveSheet;
    if (sheet.Rows.CanInsert(0,1))
    {
        RowSelection selection = sheet.Rows[0];
        selection.Insert();
    }
 
    CellIndex from = new CellIndex(0, 0);
    CellIndex to = new CellIndex(0, 1);
    CellSelection selection1 = sheet.Cells[from, to];
    selection1.Merge();
    selection1.SetValue("lqlqlq");
}
 
void exporter_CellFormatting(object sender, Telerik.WinControls.Export.CellFormattingEventArgs e)
{
    CellBorders borders = new CellBorders();
    borders.Top = new CellBorder(CellBorderStyle.Thin, new ThemableColor(System.Windows.Media.Colors.Red));
    borders.Bottom = new CellBorder(CellBorderStyle.Thin, new ThemableColor(System.Windows.Media.Colors.Red));
    borders.Right = new CellBorder(CellBorderStyle.Thin, new ThemableColor(System.Windows.Media.Colors.Red));
    borders.Left = new CellBorder(CellBorderStyle.Thin, new ThemableColor(System.Windows.Media.Colors.Red));
    e.CellStyleInfo.Borders = borders;
}

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
VLADISLAV
Top achievements
Rank 1
answered on 23 Nov 2015, 09:35 AM
System.Windows.Media.Colors.Red  Cannto resolve symbol Media, and i cant find reference to System.Windows.Media
0
Stefan
Telerik team
answered on 23 Nov 2015, 09:45 AM
This type is located in the PresentationCore assembly. Alternatively, you can use the following method to create ThemableColor from ARGB:
ThemableColor.FromArgb(0, 120, 120, 120);

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
VLADISLAV
Top achievements
Rank 1
answered on 23 Nov 2015, 09:50 AM
Thank you.
0
VLADISLAV
Top achievements
Rank 1
answered on 23 Nov 2015, 10:28 AM
Workbok created event also merge all SummaryRowsBottom. For all childRows except the last one. And also Total row on top . 
0
VLADISLAV
Top achievements
Rank 1
answered on 23 Nov 2015, 10:31 AM
Worksheet sheet = (Worksheet)e.Workbook.ActiveSheet;
            if (sheet.Rows.CanInsert(0, 1))
            {
                RowSelection selection = sheet.Rows[0];
                selection.Insert();
            }

            CellIndex from = new CellIndex(0, 0);
            CellIndex to = new CellIndex(0, 16);
            CellSelection selection1 = sheet.Cells[from, to];
            selection1.Merge();
            selection1.SetValue("Перечень разных сборов и прочих поступлений.");
            selection1.SetHorizontalAlignment(RadHorizontalAlignment.Center);
            selection1.SetFontSize(24);
0
Stefan
Telerik team
answered on 23 Nov 2015, 12:41 PM
Can you please elaborate on the issue you have as I am not sure I understand what is it?

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
VLADISLAV
Top achievements
Rank 1
answered on 24 Nov 2015, 04:35 AM

 This part deals that.

if (sheet.Rows.CanInsert(0, 1))
            {
                RowSelection selection = sheet.Rows[0];
                selection.Insert();
            }

            CellIndex from = new CellIndex(0, 0);
            CellIndex to = new CellIndex(0, 16);
            CellSelection selection1 = sheet.Cells[from, to];
            selection1.Merge();
            selection1.SetValue("Перечень разных сборов и прочих поступлений.");
            selection1.SetHorizontalAlignment(RadHorizontalAlignment.Center);
            selection1.SetFontSize(24);

0
VLADISLAV
Top achievements
Rank 1
answered on 24 Nov 2015, 04:37 AM
Without insert/merge part of this event everything fine ( pic. g16).But if i uncomment this part it gives me pic.g15. It merges also some summaryRows.
0
VLADISLAV
Top achievements
Rank 1
answered on 24 Nov 2015, 04:39 AM
And manual Unmerge restores this rows.So they shown as they must.
0
VLADISLAV
Top achievements
Rank 1
answered on 24 Nov 2015, 06:01 AM
This happens after this part
            if (sheet.Rows.CanInsert(0, 1))
            {
                RowSelection selection = sheet.Rows[0];
                selection.Insert();
            }
After row insert im getting this strange merges on the summary rows.
0
Stefan
Telerik team
answered on 24 Nov 2015, 07:57 AM
Hello Vladislav,

My guess for such behavior is if you use incorrect indexes where you insert and where you merge cells. You need to make sure you insert the row at the precise position where you want it, and then, to select the desired cells and merge them. 

More about rows and column in RadSpreadProcessing you can find in this documentation section: http://www.telerik.com/help/winforms/spreadprocessing-working-with-rows-and-columns-what-is-row-column.html

And the following section discusses cells and their usage: http://www.telerik.com/help/winforms/spreadprocessing-working-with-cells-what-is-cell.html

Merging cells discussed here: http://www.telerik.com/help/winforms/spreadprocessing-features-merge-unmerge-cells.html.

If you still experience issues, you can send a small sample (using a support ticket, where attachments are allowed) depicting the issue you have, and we will look into it.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
VLADISLAV
Top achievements
Rank 1
answered on 24 Nov 2015, 09:32 AM
Created Support ticket
0
Stefan
Telerik team
answered on 24 Nov 2015, 03:55 PM
I just wanted to update this thread that we found an issue with the merged rows, which we have logged: http://feedback.telerik.com/Project/154/Feedback/Details/176126-fix-radspreadprocessing-invalid-cells-merge-when-a-row-is-inserted

To workaround, the issue one can insert the row after the export operation is finished and the file is closed, by opening the file with the format provider and introducing the necessary changes.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
VLADISLAV
Top achievements
Rank 1
Answers by
VLADISLAV
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or