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

Export Format Problem

16 Answers 338 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sakthivel
Top achievements
Rank 1
Sakthivel asked on 15 Jun 2011, 03:47 PM
Unable to get the data format and alignment mentioned in Grid, while exporting to pdf. Please find the attached pdf and grid image. I am adding the columns  to grid from code behind by this way,

GridViewDataColumn[] grdColumn = new GridViewDataColumn[ds.Tables[0].Columns.Count];
foreach (DataColumn dColumn in ds.Tables[0].Columns)
{
    GridViewTextBoxColumn grdCol = new GridViewTextBoxColumn();
        grdCol.FieldName = dColumn.Caption;
        grdCol.HeaderText = dColumn.Caption;
        string DisplayFormat = SchB.Get_DisplayFormat(ReportID, dColumn.Caption);
        string TempDF = string.Empty;
                                        

        if (string.Compare(Convert.ToString("" + dColumn.DataType), "System.String", true) == 0)
        {
            grdCol.TextAlignment = ContentAlignment.MiddleLeft;
        grdCol.FormatString = "{0:0}";
        }
        else if (string.Compare(Convert.ToString("" + dColumn.DataType), "System.Decimal", true) == 0)
        {
            grdCol.TextAlignment = ContentAlignment.MiddleRight;
        }
    else if (string.Compare(Convert.ToString("" + dColumn.DataType), "System.DateTime", true) == 0)
        {
            grdCol.TextAlignment = ContentAlignment.MiddleRight;
            grdCol.FormatString = "{0:dd/MM/yyyy}";
        }
        else
        {
            grdCol.TextAlignment = ContentAlignment.MiddleCenter;
        }
                                        
        grdColumn[tempCount++] = grdCol;
}
gridUserReport.Columns.AddRange(grdColumn);

Regards,
Sakthivel

16 Answers, 1 is accepted

Sort by
0
James
Top achievements
Rank 1
answered on 17 Jun 2011, 05:27 PM
hi,
        I have smiler problem, i could not format the dynamic column using code
I didn't receive any error message,
       But it shows the data without format


Any help..,

with regards
Jamesraj,
 
0
Martin Vasilev
Telerik team
answered on 20 Jun 2011, 03:25 PM
Hello everyone,

It looks like there is an issue with transferring the text alignment from grid to exported pdf file. We will address this in one of the next releases. For the time being you can manually set desired alignment or apply any additional format through HTMLCellFormatting event:

void pdfExporter_HTMLCellFormatting(object sender, Telerik.WinControls.UI.Export.HTML.HTMLCellFormattingEventArgs e)
{
    if (e.GridCellInfo.ColumnInfo.Name == "City")
    {
        e.HTMLCellElement.Alignment = ContentAlignment.MiddleRight;
    }
}

Let me know if there are any other additional questions. 

Best wishes,
Martin Vasilev
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
James
Top achievements
Rank 1
answered on 21 Jun 2011, 05:35 AM
hi Martin,

        Thanks for your reply,
With your idea alignment problem is solved,
how can i format the cell when exporting,
I already  format the columns , it shows fine in grid
while exporting to PDF it does not show the format,

for example,
                 i have to format the datetime   column as "dd/MM/yyyy" , etc

with regards
Jamesraj
0
Martin Vasilev
Telerik team
answered on 23 Jun 2011, 12:39 PM
Hello James,

Thank you for getting back to me.

Actually, you can use the same event to apply any formatting while exporting to pdf:
void exportPdf_HTMLCellFormatting(object sender, Telerik.WinControls.UI.Export.HTML.HTMLCellFormattingEventArgs e)
{
    if (e.GridCellInfo.ColumnInfo.Name == "Date" && e.GridCellInfo.Value is DateTime)
    {
        e.HTMLCellElement.Value = ((DateTime)e.GridCellInfo.Value).ToString("dd MMM, yyyy");
    }
}

Do not hesitate to contact me again if you have any other questions. 

Best wishes,
Martin Vasilev
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
James
Top achievements
Rank 1
answered on 24 Jun 2011, 01:13 PM
hi Martin,
        Thanks for reply, Its working fine


With Regards,
Jamesraj
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 26 Dec 2018, 05:59 AM

Hi all,
       
      I have Issue when I Grid export to XL or pdf in windows.10 with max Resolution (1920*1080).

The issues are here. 

  1. The maximized Mdi or form is shrink to normal size automatically.
  2. Disorder the controls alignment.

The Issue is coming from the RunExport() function

Here my code is "exporter.RunExport(filename, exportRenderer);"

I attached two pics here, first one is before export Mdi picture and other one after export 

How could I overcome the issue

With Regards,
Jamsheer

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Dec 2018, 07:17 AM
Hello, Jamsheer,
     
Following the provided information, I was unable to reproduce the issue you are facing. I have attached my sample project. Am I missing something? Could you please specify the exact steps how to reproduce the problem? 

Alternatively, feel free to submit a support ticket from your account where you can provide a sample project demonstrating the problem you are facing. Thus, our support staff will gladly assist you further. Thank you in advance. 

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 26 Dec 2018, 12:34 PM

Hi Dess,

      Here I have a maximized radform. The radform is decrease its size from maximum when I click the export button and then click Save from SaveFileDialog.

Look at the gif file below
Jamsheer

0
jamsheer
Top achievements
Rank 1
Veteran
answered on 26 Dec 2018, 12:42 PM

Hi Dess,
      I have a maximized radform. The form is decreased its size from maximum when I click the export button an then click Save in SaveFileDialog.

Look at the gif file to reffer more.

Thank you
Jamsheer 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Dec 2018, 08:43 AM
Hello, Jamsheer,

The provided gif file is greatly appreciated. However, it is not enough for me to replicate the issue locally. Have you tested the export behavior with the provided sample project from my previous reply? Is the issue reproducible with it? What is the Telerik UИ for WinForms version that you are currently using?

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 27 Dec 2018, 10:58 AM

Hi Dess,
      Thanks for your fast replay.

I tested with your code provided sample project from your previous reply, But its not solved my issue.

I am using "Visual Studio 2015".

Here is my code I used in my project.

public Form1()
        {
            InitializeComponent();
 
            DataTable table = new DataTable();
            table.Columns.Add("Id", typeof(int));
 
            for (int i = 0; i < 10; i++)
            {
                table.Columns.Add("Column " + i, typeof(string));
            }
 
            for (int i = 0; i < 100; i++)
            {
                DataRow row = null;
                row = table.NewRow();
                row["Id"] = i + 1;
 
                for (int j = 0; j < table.Columns.Count - 1; j++)
                {
                    row["Column " + j] = "Name " + j * i;
                }
 
                table.Rows.Add(row);
            }
 
            this.radGridView1.DataSource = table;
            this.radGridView1.Rows[3].IsPinned = true;
            this.radGridView1.Columns[2].IsPinned = true;
            this.radGridView1.Columns[2].PinPosition = Telerik.WinControls.UI.PinnedColumnPosition.Left;
        }
 
        private void radButton1_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.FileName = "exportedFile";
            dialog.Filter = "xlsx files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
 
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                ExportData(dialog.FileName);
            }
        }
 
        void ExportData(string fileName)
        {
            SpreadExportRenderer renderer = new SpreadExportRenderer();
            GridViewSpreadExport spreadExporter = new GridViewSpreadExport(this.radGridView1);
            spreadExporter.FreezeHeaderRow = true;
            spreadExporter.FreezePinnedColumns = true;
            spreadExporter.FreezePinnedRows = true;
            spreadExporter.ExportVisualSettings = true;
            spreadExporter.SheetMaxRows = ExcelMaxRows._1048576;
            spreadExporter.ExportFormat = SpreadExportFormat.Xlsx;
            spreadExporter.FileExportMode = FileExportMode.CreateOrOverrideFile;
            spreadExporter.RunExport(fileName, renderer);
        }

Can I attach my project zip file here? If yes, how could I do

This issue is in Windows10 with maximum resolution(1980*1080) 
Thank you
Jamsheer 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Dec 2018, 12:48 PM
Hello, Jamsheer, 

I have tested my sample project with resolution 1920 x 1080 and it behaves as expected. After creating a new form with the provided code snippet, the problem is still not reproducible on my end. It seems to be something specific in the environment that you are using.

The allowed extensions in the forum threads are: .gif, .jpg, .jpeg, .png. That is why I kindly asked you to submit a ticket from your account where you can provide a full description of the precise case together with your sample project. Thus, our support staff will gladly will be able to make an adequate analysis of the precise case and assist you further. Thank you in advance. 

Thank you for your understanding.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 28 Dec 2018, 06:46 AM

Hi Dess,
      I run the project that you specified above, But there also getting the same issue.

The issue is coming only in "Windows 10 OS, Resolution (1920 x 1080)".

You should check with Windows 10 OS, Resolution (1920 x 1080)

I attached the gif file with run you specified project.

Thank you.

Jamsheer 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Dec 2018, 01:52 PM
Hello, Jamsheer, 

The provided gif file was very useful since it clearly shows how th font was changed after exporting the grid. I was able to replicate the problem if the application is run on higher than 100% DPI scaling. Note that the grid export uses the RadSpreadProcessing library. Telerik’s document processing library (RadSpreadProcessing, RadWordProecessing or RadPdfProcessing) is referencing assemblies which are used in WPF. All WPF-based applications are DPI-aware by default and this is declared in the manifests of the WPF assemblies. Therefore, if you use the document processing library in WinForms applications that are not DPI-aware, they might suddenly become DPI-aware at run time when you instantiate a type from the DPL assemblies (when the DPL assemblies are loaded by the CLR, this will also load the WPF assemblies which they depend on, which in turn will make the application DPI-aware). If you intend to use your application on machines where the DPI scaling is larger than 100 percent, you should explicitly set the application to be DPI-unaware right before running the export logic:

private void workbookTestButton_Click(object sender, EventArgs e)
{
    SetProcessDpiAwareness(_Process_DPI_Awareness.Process_DPI_Unaware);
    Workbook wb = new Workbook();
}
   
[DllImport("shcore.dll")]
static extern int SetProcessDpiAwareness(_Process_DPI_Awareness value);
   
enum _Process_DPI_Awareness
{
    Process_DPI_Unaware = 0,
    Process_System_DPI_Aware = 1,
    Process_Per_Monitor_DPI_Aware = 2
}

I have tested it on my end and it seems to work properly.

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
jamsheer
Top achievements
Rank 1
Veteran
answered on 31 Dec 2018, 05:07 AM
Hi Dess,
        
      Thank you, Its worked properly.
Jamsheer
0
Jaco Van Zyl
Top achievements
Rank 1
answered on 06 Jan 2019, 03:14 PM

Thank you!

I ran into the same problem today and your post fixed my error.

Tags
GridView
Asked by
Sakthivel
Top achievements
Rank 1
Answers by
James
Top achievements
Rank 1
Martin Vasilev
Telerik team
jamsheer
Top achievements
Rank 1
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
Jaco Van Zyl
Top achievements
Rank 1
Share this question
or