Articles in this section
Category / Section

How to rename the sheet programmatically in React Spreadsheet?

2 mins read

This knowledge base explains you how to rename the sheet programmatically in React Spreadsheet. On a button click event, you have to fetch the active sheet model by using the sheet index and modify the sheet name. After modification, assign the modified sheet model to the sheets property.

[index.js]

import * as React from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
import { getUniqueID } from '@syncfusion/ej2-base';

function App() {
 let spreadsheet;

 const renameSheetHandler = () => {
   const sheets = spreadsheet.sheets;
   // You can pass the sheet index based on your need in sheet object and assign the sheet name.
   // getUniqueID('test') - Return the unique ID along test content like "test_{numeric value}"
   sheets[spreadsheet.activeSheetIndex].name = getUniqueID('test');
   // Instead of call refresh method, you can assign sheet property as like below for sheet refresh
   spreadsheet.sheets = sheets;
 };
 return (
   <div>
     <spreadsheetcomponent ref="{(ssObj)" ==""> {
         spreadsheet = ssObj;
       }}
     &gt;</spreadsheetcomponent>
     <button>Rename Sheet</button>
   </div>
 );
}
export default App;

const root = createRoot(document.getElementById('sample'));
root.render(<app>);

Stackblitz Sample: https://stackblitz.com/edit/react-nqntbt-96sc5x?file=index.js

Output:

output.gif

For more details refer to the below attached links.

https://ej2.syncfusion.com/react/documentation/spreadsheet/worksheet
https://ej2.syncfusion.com/react/documentation/api/spreadsheet/#activesheetindex
https://ej2.syncfusion.com/react/documentation/api/spreadsheet/#sheets

Conclusion
I hope you enjoyed learning on how to update the sheet name in the sheets tab programmatically in React Spreadsheet.

You can refer to our React Spreadsheet feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our React Spreadsheet Example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied