Click here to Skip to main content
11,408,708 members (62,643 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Excel Data
Hai guys..

I'm build intarface for detection size object.
I get result the size object from binary image from camera capture and i need record size object data to excel.

I was tried this code to show and record size data from my interface using excel.
private void dataToolStripMenuItem_Click(object sender, EventArgs e)
                Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
                Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
                Worksheet ws = (Worksheet)xla.ActiveSheet;
                xla.Visible = true;
                ws.Cells[1, 1] = "No";
                ws.Cells[1, 2] = "Size Data";
                string[] arraySize;
                arraySize = new string[101];
                for (int i = 3; i != (arraySize.Length); i++)
                    string sizeData = labelSize.Text;
                    ws.Cells[i, 2] = sizeData;

But code above just give me "one data" when i clicked button data and it's still same until rows 100.
And it doesn't what i meant.
I need the size object from the text box in intraface will record to excel when i'm click the button data, and excel give me result size data in runtime from interface.
So, anyone can help me to get runtime size data and record it to excel?
Posted 26-Nov-12 4:38am
Edited 26-Nov-12 4:58am
Krunal R at 26-Nov-12 9:53am
What code man ???
zaenal arifin at 26-Nov-12 10:02am
i have edited my question..
digimanus at 29-Nov-12 4:57am
i != (arraySize.Length is always true you mean
i < (arraySize.Length
zaenal arifin at 4-Dec-12 9:30am
Thank you digimanus, for your respon.. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

zaenal arifin at 26-Nov-12 10:01am
Thank you Krunal for the link.. :)
Krunal R at 26-Nov-12 10:03am
Krunal R at 26-Nov-12 10:08am
Have you rejected the solution ??
zaenal arifin at 26-Nov-12 10:24am
I'm so sorry Krunel, the link can't solve my problem coz i'm not using data grid view in my project..can you give me some advice from my code?it's that right or wrong?
Krunal R at 26-Nov-12 10:28am
Oh, I thought that just because of current forum issue, Answer has been rejected..
So here I have updated my solution.. take a look at that.. perhaps that could help you ...
zaenal arifin at 27-Nov-12 8:51am
Thank you Krunal.. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

zaenal, you can realize your task by below code, but beore you realize this code, you have to download this C# Excel[^] component, it does not need to install MS Excel, it works fine in my project.if you have any problem, you can tell me.
using System.Threading;
using Spire.Xls;
namespace toExcel
    public partial class Form1 : Form
        private bool stop = false;
        private Workbook workbook = null;
        private Worksheet worksheet = null;
        private int rowIndex = 0;
        private String fileName = null;
        public Form1()
        private void labelSize_TextChanged(object sender, EventArgs e)
            if (stop)
            String no = String.Format("No. {0}", rowIndex);
            worksheet[rowIndex, 1].Text = no;
            worksheet[rowIndex, 2].Text = this.labelSize.Text;
        private void InitWorkbook()
            workbook = new Workbook();
            worksheet = workbook.Worksheets[0];
            worksheet.Name = "image size";
            worksheet.Range[1, 1].Text = "No";
            worksheet.Range[1, 2].Text = "Size Data";
            rowIndex = 1;
            fileName = String.Format("image-size-{0}.xls", Guid.NewGuid());
        private void btnDemoStart_Click(object sender, EventArgs e)
            this.btnOpenExcel.Enabled = false;
            this.stop = false;
            Random random = new Random();
            new Thread(() =>
                    int width = random.Next(1024);
                    int height = random.Next(1024);
                    this.Invoke(new Action(() =>
                        this.labelSize.Text = String.Format("{0}, {1}", width, height);
        private void btnDemoStop_Click(object sender, EventArgs e)
            this.stop = true;
            this.btnOpenExcel.Enabled = true;
        private void btnOpenExcel_Click(object sender, EventArgs e)
zaenal arifin at 4-Dec-12 9:33am
Lacy00, sorry for late reply.. thank you for the code and i'll try it.. But i want to asking to you, what the function of Spire in my project?
zaenal arifin at 4-Dec-12 10:04am
Is that free for download?
Lacy00 at 11-Dec-12 21:00pm
Yes, you can freely download it, but it is a commercial library,if you have not a license, when you use it it is in evaluation mode. there is an evaluatio warming in the document
zaenal arifin at 11-Dec-12 23:29pm
Can u send your interface by email?because i was tried but i don't how to build interface like your code.. i'm very newbie in c# language, i really need your help lacy to finish my project..
Lacy00 at 13-Dec-12 1:29am
I am very happy to help you, but I do not know your e-mail and how can I send it to you?
zaenal arifin at 14-Dec-12 2:43am
This is my email
If allowed, i need your form application with code above but if didn't you just screening that GUI. So, i can see what you put on GUI.
Thank you Lacy for your help..
zaenal arifin at 18-Dec-12 11:41am
Thank you Lacy, u solve my problem... :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

zaenal arifin at 27-Nov-12 8:53am
Thank you for the link Lacy.. :)
Can i insert value from text box to excel without using datagridview?
Lacy00 at 27-Nov-12 22:34pm
Yes, it can export data from text box to excel
zaenal arifin at 28-Nov-12 10:44am
How it can be done lacy? i was tried code above,it can export but only one value not all. My textbox display a dynamic number, so it's value always change...
I need help to record all value in textbox when the program is running..
Lacy00 at 28-Nov-12 22:27pm
zaenal, when I solve it, I will tell you in this forum.

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

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 284
2 Maciej Los 155
3 Peter Leow 140
4 PIEBALDconsult 130
0 Sergey Alexandrovich Kryukov 8,626
1 OriginalGriff 6,855
2 Maciej Los 3,322
3 Abhinav S 3,238
4 Peter Leow 3,034

Advertise | Privacy | Mobile
Web04 | 2.8.150414.5 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100