C++Language FeatureLearn C++

Learn To Copy Excel Clipboard To A Windows StringGrid In Modern C++

woman coding on computer

Clipboard, also called as the paste buffer, is is a buffer which operating systems provide to copy things (texts, bitmaps, tables etc.) for short term and transfer within and between application programs. The clipboard is usually temporary and unnamed, and its contents reside in the computer’s memory.

In C++ Builder there are good components to use Excel forms, excel supported Grid components etc. In this post example we would like to copy excel table to clipboard and paste it to StringGrid in C++ Builder. This method is good to copy data from excel tables to your component members.

Clipboard from an Excel consists L’\t tab characters , so first we should delimitate each lines. We can use this delimiter function for each rows.

We can use Clipboard() function to get all lines as below.

This text includes all table with both L’\n’ return characters for each row and L’\t’ tab characters for each columns. We can easily see each members with this small example below. We need to delimit clipboard to rows first and delimit each row to columns. We need these to support Unicode strings.

So, we can delimit each lines of clipboard text with return and tab characters by using our split() function as below;

We should do this operation in two for loops for columns and rows. So we can set cell of grid at i,j as below;

If we combine all together, full C++ Builder VCL codes of this example with a StringGrid, a Memo and a Button should be as below;

And if you copy a table and paste it with a Button1, the result will as below

StringGrid supports Unicode Strings that means you can also safely copy all tables including texts in all languages. In theory there should be no problem, if there is check your locale settings or may be you need better locale settings in your codes and may be better font supports that language.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?