I would like to write a series of articles, and the system introduces C # operation Excel. It's too nervous, plus a lot of introduction to the C # operation Excel in 9cbs blog, and record some tips. This article should also be updated later, gradually writing some of the small skills that Excel encountered. This kind of tip may not be very meaningful for most people, but it is still not very good for most when it is useful. After all, many methods of operating Excel in C # have been greatly different. Oh, don't put it on the home page. 1: Operate merge unit
Range Merge () and unmeric () methods must be familiar, and the Range object has two member properties:
(1) Mergecells attribute: BOOL type, is a merged cell. In C #, if it is not a merging unit, an exception will be generated.
(2) Mergearea Attribute: For the merge unit, the RANGE object of the merged cell will be returned.
The following method can be used to check and populate the merging cells in Excel:
Static Bool CheckRangismerge (Range RNG)
{
Bool BMERGE = FALSE;
Try
{
IF (RNG.Mergecells.Tostring () == BOOL.TRUESTRING)
{
Bmergen = True;
Excel.Range mrng = rng.mergeare;
mrng.unmerge ();
For (int i = 0; i { For (int J = 0; j { RNG.GET_OFFSET (I, J) .value2 = rng.value2; } } } } Catch (Exception EX) { Console.writeline ("Error: {0}", EX.MESSAGE.TOSTRING ()); Bmerge = false; } Return Bmerge; } Note: When calling, it is best to only pass a cell composed of RANGE. The reason is as follows: If RANGE (A1, B1) is a merge unit, the result of TRUE will not be obtained when the merge (A1, C1) is checked.