C # Use the Spread6.0 full Raiders

Source: Internet
Author: User
Tags ole table name zip
Introduction (i) load Spread6.0 in C #

nmd002 version of "C # load Spread6.0 full Raiders"

First, the DLL file that contains Spread6.0 is referenced in the reference.
(If you first put the C #, then Ann's spread may not be loaded, is automatically referenced.) )
Second, select a tab in the control box that you want to place the spread control in.
Right click on the inside, select "Add/Remove Items", if your machine is not fast enough, please go to the toilet first.
Then, in the "COM component" of the dialog box, look for
"Farpoint Spread 6.0",
"Farpoint Spread 6.0 (OLE DB)",
"Farpoint Spread Preview 6.0",
"Farpoint Spread Preview 6.0 (OLE DB)",
These four options are hook-and-tick.
Finally, the point is OK.
In this way, the spread four controls appear in the current tab of your control box.
Other usages are similar to those used in VB.

Finally, I would like to stress that the Spread6.0 itself, although compatible with C #, is not designed for C #,
Although in C # can be used, but to several transformations, many detours, no more than under the development of VB Easy,
Instead, it seems more incongruous and difficult. Do not use it under C # unless the customer strongly requests it!

=====================================
The above content and the following content are I wrote in C # form application, the Web application has not tried.
Please choose according to your own needs, in addition, please reprint elsewhere, keep the author Nmd002 's signature, thank you!
=====================================


(ii) Use of Spread6.0 in C #

nmd002 version of "C # use Spread6.0 full Raiders"

Some people will say, in C # with spread what is great, not with VB in the same simple?

People who can say such things generally have two things in common:
A person who has never done it, take it for granted, and another who has done many things, must say so.

Yes, the principle is the same, there is no discrepancy. But actually doing it is a different thing.

"The biggest problem with using spread in C # is not how spread is used,
Instead, the data for the new type of result set (DataSet) is displayed in the spread. ”

People who actually do projects with spread know that spread is not primarily used to bind data,
It is used to display and receive data because most of the data input needs to be validated.
Binding is a means of lack of flexibility in calibration, which is not conducive to data security.

So what is the difference between the result set in C # and the result set in VB?
The result set in C # is stored in the object as XML,
And the result set of VB is in the form of an array to save in the object.

<NewDataSet>
<authors>
<au_id>172-32-1176</au_id>
<au_lname>White</au_lname>
<au_fname>Johnson</au_fname>
<phone>408 496-7223</phone>
<address>10932 Bigge rd.</address>
<city>menlo park</city>
<state>CA</state>
<zip>94025</zip>
<contract>true</contract>
</authors>
<authors>
<au_id>213-46-8915</au_id>
<au_lname>Green</au_lname>
<au_fname>Marjorie</au_fname>
<phone>415 986-7020</phone>
<address>309 63rd St. #411 </address>
<city>Oakland</city>
<state>CA</state>
<zip>94618</zip>
<contract>true</contract>
</authors>
......
<authors1>
<Column1>23</Column1>
</authors1>
</NewDataSet>

This is the instance string that is displayed when the content in a dataset is converted, where the <authors> tag is the record of the first table in the result set, and the <authors1> The contents of the label are the contents of another table in this result set.
This shows that the contents of the dataset are stored in an XML string defined by the <NewDataSet> tag.
Different tables are labeled with different names, each record of each table is labeled with its own field name to identify its own field values.
So, if you want to do this: read the values in the specified table and write to the spread cell, just learn to take all the records from the specified table in the dataset and write the values to the corresponding cells.

I have two successful methods in practice:
1, double cycle directly from the dataset to fill in the corresponding spread cell.

Axvaspread1.maxrows = Rs. Tables[tablename]. Rows.Count;
Axvaspread1.maxcols = Rs. Tables[tablename]. Columns.count;
Axvaspread1.row=1;
axvaspread1.col=1;
Axvaspread1.row2=axvaspread1.maxrows;
Axvaspread1.col2=axvaspread1.maxcols;

int i,j;
For (I=1;i<=rs. Tables[tablename]. rows.count;i++)
{
For (J=1;j<=rs. Tables[tablename]. columns.count;j++)
{
Axvaspread1.row=i;
Axvaspread1.col=j;
Axvaspread1.value =rs. Tables[tablename]. ROWS[I-1][J-1]. ToString ();
}
}
In this example, RS is a DataSet object and AxvaSpread1 is an Vaspread object instance.
TableName is the specified table name.

2, by obtaining the dataset's XML string, and convert it into a two-dimensional table (using "Horizontal tab" to distinguish the field, "line" to distinguish the large string of records), as the result set of VB in the Clipboard content of the test, write directly to the spread object.

Axvaspread1.maxrows = Rs. Tables[tablename]. Rows.Count;
Axvaspread1.maxcols = Rs. Tables[tablename]. Columns.count;
Axvaspread1.row=1;
axvaspread1.col=1;
Axvaspread1.row2=axvaspread1.maxrows;
Axvaspread1.col2=axvaspread1.maxcols;

String Xmlstr=rs. GETXML (). ToString ();
String steatstr= "\\</" + tablename + "\\>";
Generates a replacement string "\</authors\>" for a record node
Using regular expressions to convert a string with XML as Axvaspread1.clip acceptable format
Xmlstr=regex.replace (Xmlstr, @ "[\n\r\v\t]*", "");
Remove unused whitespace from all spaces in the string: carriage return, line feed, horizontal tab, Vertical tab. How much is there to go?
Xmlstr=regex.replace (Xmlstr, @ "\< (|/) newdataset\>", "");
Remove the XML string generated by the dataset: Fixed start tag <NewDataSet> and fixed end tag </NewDataSet>
Xmlstr=regex.replace (Xmlstr, @ "\<" ([^/]*) \> "," ");
Remove all start tags FOR XML string: <newdataset>,<au_id>,<city>,<authors&gt ...
Xmlstr=regex.replace (Xmlstr, @steatstr, "\ r");
Replace the end tag of the specified table record with a newline character:</authors> => \ r
Xmlstr=regex.replace (Xmlstr, @ "\</[\w]*\>", "T");
Change the end label of another content to a horizontal tab:</au_id> => \ t
axvaspread1.clip=xmlstr;//data content into spread objects

The regex is a regular object, and the other ibid.

In fact, according to the above ideas, there are other ways to find, such as a custom class, the storage structure is exactly the same as the result set of VB storage structure, and then write a method specifically placed and taken out, as long as you know enough about the recordset, there is no problem at all.
or other methods, as long as the dataset and recordset to achieve the content conversion, how to achieve all.
After all, catching mice is a good cat!



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.