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.

Sat Oct 09, 2021 12:38 pm

I am trying spire.xls to get a feeling of it's capabilities. I'm having trouble finding the exact information I need.
1. How would I put all of the open workbooks into a menu combobox.
2. How would I put all of the visible worksheets from a selected workbook into a menu combobox.
3. How would I transfer information in a c# combbox to specific cell(row,column) of the selected excel sheet.

Thanks for you help,
Jeff

jrdnolandbear
 
Posts: 2
Joined: Fri Oct 08, 2021 8:37 pm

Mon Oct 11, 2021 8:38 am

Hello,

Thank you for your inquiry.
For questions 1 and 2, do you want to write the names of all excel files in the combobox, and write the names of all the visible worksheets of the excel file selected in the first combobox in another combobox? If it is, in fact this operation has nothing to do with our product. Please check the code below to write excel file name and worksheet name into combobox respectively.
Code: Select all
//Write excel file name into combobox1
comboBox1.Items.Add("excel1.xlsx");
comboBox1.Items.Add("excel2.xlsx");
comboBox1.Items.Add("excel3.xlsx");
comboBox1.Items.Add("excel4.xlsx");
...

//Write the names of all visible worksheets of the specified excel file into the combobox2
comboBox2.Items.Add("sheet1Name");
comboBox2.Items.Add("sheet2Name");
comboBox2.Items.Add("sheet3Name");
...

For question 3, our Spire.XLS supports writing content in specific cells of the worksheet, please refer to the code below.
Code: Select all
 //Get the excel file name selected in the combobox
 string files = this.comboBox1.Text;
 Workbook book = new Workbook();
 //Load excel file
 book.LoadFromFile(files);
 //Get the worksheet according to the worksheet name
 Worksheet sheet = book.Worksheets[this.comboBox2.Text];
 //Write the information in combobox1 into cell "A4"
 sheet.Range["A4"].Text = this.comboBox1.Text;
...
 //Save the file
 book.SaveToFile("", FileFormat.Version2013);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Mon Oct 11, 2021 9:36 am

Thank you Annika, I want to work with an excel sheet that is already opened, hence putting all the workbooks and worksheets in comboboxes. Most of the code ZI've seen starts with Spire.XLS either loading a specific workbook or creating a new one.

Just want to be able to work with an existing workbook, is that possible?

Thanks,
Jeff

jrdnolandbear
 
Posts: 2
Joined: Fri Oct 08, 2021 8:37 pm

Mon Oct 11, 2021 9:58 am

Hi,

Thank you for your feedback.
Yes, our Spire.XLS supports operating on existing Excel files. Please refer to the following code. If I misunderstand your requirements, please provide the further details.
Code: Select all
Workbook book = new Workbook();
book.LoadFromFile(your existing excel file);
//book.LoadFromStream(stream);
...

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS