Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Jan 09, 2019 3:31 pm

I am Back!!! :D im searching for a way to Write Data to an Sheet without set location like sheet.Range["A1"],sheet.Range["A2"]... and so on. i must iterate through columns and rows to write data to this cells that actualy empty.

Semjasa
 
Posts: 36
Joined: Wed Dec 19, 2018 11:50 am

Thu Jan 10, 2019 2:53 am

Hi Semjasa,

Thanks for your inquiry.
There is a property IsBlank to judge if a cell is empty, please have a try. Sample code for your kind reference:
Code: Select all
            foreach (CellRange cs in sheet.Cells)
            {               
                if (cs.IsBlank)
                {
                    //write your data
                    cs.Value = "data";
                }
            }


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Jan 10, 2019 7:50 am

this sheet is always empty. what is to do that i can write in an empty sheet :?

sorry i have forgotten to write this...
at first this workbook is created and empty and i want to insert new data into a sheet from "A1" to "**" i dont know how big this Dataobject is

Example: data: [ ["Person1", "Person2", "Person3"], [100,200,300], [10,20,30] ]
| A | B | C
1 | Person1 | 100 |10
2 | Person2 | 200 | 20
3 | Person3 | 300 | 30

Or more Data

Semjasa
 
Posts: 36
Joined: Wed Dec 19, 2018 11:50 am

Thu Jan 10, 2019 10:00 am

Hi Semjasa,

Please refer to below code.
Code: Select all
            string[,] data = new string[,] { { "Person1", "Person2", "Person3" }, { "100", "200", "300" }, { "10", "20", "30"}};       
           int nRow = data.GetLength(0);  // The dimensions of rows.
           int nCol = data.GetLength(1); // The dimensions of colums.
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];
            for (int i = 0; i < nCol; i++)
            {
                for (int j = 0; j < nRow; j++)
                {
                    //insert the data
                    sheet.Range[i + 1, j + 1].Value = data[j, i];
                }
            }
            workbook.SaveToFile("16104.xlsx", ExcelVersion.Version2010);


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Jan 10, 2019 1:57 pm

thank you,
again :wink:

Thomas

Semjasa
 
Posts: 36
Joined: Wed Dec 19, 2018 11:50 am

Fri Jan 11, 2019 1:52 am

Hi,

You are welcome :wink:
Just feel free to contact us if you need any help.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Nov 22, 2019 2:01 pm

Hello,
Along these same lines, we would like to use Spire to write an Aggregate xlsx to track data like such:
Row 1 has data
Row 2 has data

Is there a way to find the next empty ROW(Row 3 in this case) then begin to write data in that first empty cell?

Thanks in advance!

kkindler
 
Posts: 1
Joined: Fri Nov 22, 2019 1:55 pm

Mon Nov 25, 2019 3:02 am

Hi,

Thanks for your inquiry.
We have the property row.IsBlank which could judge if the row is empty. You could refer to below sample code:
Code: Select all
            for (int i = 0; i < sheet.Rows.Length; i ++ )
            {
                if (i + 1 < sheet.Rows.Length)
                {
                    CellRange row = sheet.Rows[i + 1];
                    if (row.IsBlank)
                    {
                        row.Cells[0].Value = "test";
                        break;
                    }
                }
            }

If this doesn't meet your requirement, please provide your input and desired Excel file for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.XLS