WPF SpreadSheetGear electronic form, wpfspreadsheetgear

Source: Internet
Author: User

WPF SpreadSheetGear electronic form, wpfspreadsheetgear

We often encounter the function development that generates an Excel interface and operates on it.

For example, in the following interface, we need To add a menu button "Columns To Rows Transform" in the menu To convert multiple Columns into multiple Rows in batches.

You can use the Interop component to add the menu appending function. I will write a Demo later for you to view. But this is a little troublesome. You need to manually register the Excel environment every time you start Excel.

We can use third-party controls to provide solutions:

1. Install the Telerik Control

If it is convenient, we recommend that you use the next Demo.

 

2. Create a Telerik project through Telerik in. It is convenient to create a template.

3. Add menu button

4. Add event processing in the background.

Private void ColumnsAndRowsTransformButton_OnClick (object sender, RoutedEventArgs e) {try {var workbook = viewModel. workbook; var sheet = workbook. activeWorksheet; var ranges = sheet. viewState. selectionState. selectedRanges; int insertRowsCount = 0; foreach (var range in ranges) {if (range. isSingleCell) {continue;} var firstRange = range. fromIndex; // Foreach Rows for (int I = 0; I <range. rowCoun T; I ++) {int rowIndex = firstRange. rowIndex + I + insertRowsCount; int columnIndex = firstRange. columnIndex; int currentRowAddRows = 0; // value for (int j = 1; j <range. columnCount; j ++) {var cellValue = sheet. cells [rowIndex, columnIndex + j]. getValue (). value; if (string. isNullOrEmpty (cellValue. rawValue) {continue;} sheet. rows. insert (rowIndex + 1 + currentRowAddRows, 1); currentRowAddRows ++; sheet. ce Lls [rowIndex + j, columnIndex]. setValue (cellValue. rawValue); sheet. cells [rowIndex, columnIndex + j]. setValue ("");} // copy the uplink content of the row's cell int index = 0; do {var upValue = sheet. cells [rowIndex, index]. getValue (). value; if (string. isNullOrEmpty (upValue. rawValue) & index> 50) {break;} if (index! = ColumnIndex) {for (int j = 0; j <currentRowAddRows; j ++) {sheet. cells [rowIndex + 1 + j, index]. setValue (upValue) ;}} index ++;} while (true); insertRowsCount ++ = currentRowAddRows ;}} catch (Exception ex) {MessageBox. show (ex. message );}}
View Code

This Telerik control is quite convenient.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.