unvell / ReoGrid

Fast and powerful .NET spreadsheet component, support data format, freeze, outline, formula calculation, chart, script execution and etc. Compatible with Excel 2007 (.xlsx) format and working on .NET 3.5 (or client profile), WPF and Android platform.
https://reogrid.net
MIT License
1.34k stars 395 forks source link

When will WPF printing will be supported ? #101

Open borislavnnikolov opened 6 years ago

borislavnnikolov commented 6 years ago

For now I am using this:

 string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".xlsx";

            this.Grid.Save(fileName, unvell.ReoGrid.IO.FileFormat.Excel2007);

            Process myProcess = new Process();

            try
            {
                myProcess.StartInfo.UseShellExecute = true;
                myProcess.StartInfo.FileName = fileName;
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.StartInfo.Verb = "print";
                myProcess.Start();
            }
            catch (Exception e)
            {
                throw e;
            }
ks1974in commented 5 years ago

There are two approaches you can take until the print functionality is available as far as I know

  1. Use the winforms version for printing and the wpf version for display. [You need to use a separate project [a dot net framework class library referencing reogrid for winforms ]create a dummy form which is hidden, and then populate the grid on that form and use it for print and print preview]. You also need to recompile the winforms version after changing the assembly name since both assembles [winforms and wpf] are name unnvell.ReoGrid.dll and one will overrite the other, or vice versa.

  2. Use the winforms version for both display and printing in your wpf app. You can do this using the following XAML markup

    <WindowsFormsHost Width="800" MaxHeight="250"  VerticalAlignment="Stretch">
     <rg:ReoGridControl x:Name="grid" />
    </WindowsFormsHost>

You have to add a reference to System.Windows.Forms and WindowsFormsIntegration dlls. https://stackoverflow.com/questions/10717305/how-to-add-winform-user-control-into-wpf-so-that-i-can-reference-it-in-the-xaml

I followed the second approach because of a bug I resolved in the winforms version but the fix did not work in the wpf version. #203

jingwood commented 3 years ago

duplicate of #69