Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,

I am using property grid control which display the stat values of an image .
I want to export those displayed values to excel.
its a window application in c# below the code I'm using and its working fine.It display statistics of image in property grid control...


I dont know how to export these statistic values from property grid to excel ...


I need code for how to export displayed values in property grid to excel or any other

[Edit]
C#
public class ImageStatisticsWindow : Content
{
    private System.Windows.Forms.PropertyGrid propertyGrid;
    private System.ComponentModel.Container components = null;
    private SaveFileDialog saveFileDialog1;
    private Button button1;
    private SaveFileDialog saveFileDialog2;
    private int currentImageHash = 0;
    public ImageStatisticsWindow()
        
    {
        InitializeComponent();
    }

    internal class ColorImageStatisticsDescription
    {
        private ImageStatistics statRGB;
        private ImageStatisticsHSL statHSL;
        private ImageStatisticsYCbCr statYCbCr;
     
        [Category("0: General")]
        public int PixelsCount
        {
            get { return statRGB.PixelsCount; }
        }
       
        [Category("0: General")]
        public int PixelsWithoutBlack
        {
            get { return statRGB.PixelsCountWithoutBlack; }
        }

        [Category("1: Red ")]
        public int RedMin
        {
            get { return statRGB.Red.Min; }
        }
       
        [Category("1: Red ")]
        public int RedMax
        {
            get { return statRGB.Red.Max; }
        }
    }


    public void GatherStatistics(Bitmap image)
    {
        if (image != null)
        {
            if (currentImageHash == image.GetHashCode())
                return;
            currentImageHash = image.GetHashCode();
        }
        else
        {
            propertyGrid.SelectedObject = null;
            return;
        }

        System.Diagnostics.Debug.WriteLine("--- Gathering stastics");

        if (image.PixelFormat == PixelFormat.Format24bppRgb)
        {
    
            Capture = true;
            Cursor = Cursors.WaitCursor;

            ColorImageStatisticsDescription statDesc = new ColorImageStatisticsDescription(image);
      
            propertyGrid.SelectedObject = statDesc;
            propertyGrid.ExpandAllGridItems();
            
            Cursor = Cursors.Arrow;
            Capture = false;
        }
        else
        {
            propertyGrid.SelectedObject = null;
        }
    }


    public ColorImageStatisticsDescription(Bitmap image)
    {
        int width = image.Width;
        int height = image.Height;
  
        BitmapData imgData = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    
        statRGB = new ImageStatistics(imgData);
        statHSL = new ImageStatisticsHSL(imgData);
        statYCbCr = new ImageStatisticsYCbCr(imgData);

        image.UnlockBits(imgData);
    }
}
Posted
Updated 10-Sep-13 5:28am
v3
Comments
[no name] 19-Aug-13 7:52am    
"I want to", okay then you have permission to proceed.
Akbar Ali Hussain 19-Aug-13 18:40pm    
So you want somebody to write code for you?
lukeer 10-Sep-13 11:47am    
Something's wrong with the intendation.
public ColorImageStatisticsDescription(Bitmap image) is a constructor and it's outside of its class.

Please use the "Improve question" link and repair that.

On your question:
The important data seems to be in statRGB, statHSL and statYCbCr. Is that Correct?

1 solution

You don't really want to export using the PropertyGrid. Instead, the grid is a view on a set of data (your image). You want to create another view that's saved to disk instead of displayed on-screen.

PropertyGrid heavily relies on Reflection[^]. This way, it can display properties of a wide variety of objects.

Since you're mentioning a given type of data (image), most likely it's easier to write an export specifically for the image class you're using.

Please update your question (using the "Improve question" link) and provide some code that shows what you want to export.

And then there's the "to excel" part. I've never done that. Always got away with one sort of CSV file format or the other.
 
Share this answer
 
Comments
lukeer 6-Sep-13 9:17am    
I've read that a fortnight ago, understood your question back then and answered accordingly.
The interesting part for you should not be the PropertyGrid. It's the class you're creating instances of to display their values in it.

Use the "Improve question" link to show the code of that class so we can design an export into it.
lukeer 10-Sep-13 11:32am    
I told you twice to use the "Improve question" link to update your question.

You're totally right to leave a comment here so that I get noticed about you having posted something. But the code belongs in the question. There it is to be wrapped in <pre lang="c#">YourCodeHere();</pre> tags so it will get nicely formatted.

FTFY, you're welcome. Now have a look how much better code is readable when formatted properly in the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900