📄 wksheet.h
字号:
Delete a row in the worksheet
Parameters:
nPos = Row number with zero offset
Return:
TRUE if Succesful; otherwise FALSE
Example:
Worksheet wks("Data1");
ASSERT(wks.DeleteRow(10)); //Delete a row from 10th row
SeeAlso:
Worksheet::InsertRow, Worksheet::AppendRows
*/
BOOL DeleteRow(int nPos);
/**
Remarks:
Append rows to the worksheet
Parameters:
nRows = Number of rows to append; 1 by default
Return:
True = Succesful; otherwise FALSE
Example:
Worksheet wks("Data1");
ASSERT(wks.AppendRows(10));
SeeAlso:
Worksheet::InsertRow, Worksheet::DeleteRow
*/
BOOL AppendRows(int nRows = 1 );
/**
Remarks:
Delete a column in the worksheet
Parameters:
nCol = Column number with zero offset
Return:
True = Succesful; otherwise FALSE
Example:
Worksheet wks("Data1");
ASSERT(wks.DeleteCol(0));
SeeAlso:
Worksheet::InsertCol
*/
BOOL DeleteCol(int nCol);
/**
Remarks:
Delete a range of data in the worksheet
Parameters:
nRowBegin = Beginning row number with zero offset
nColBegin = Beginning column number with zero offset
nRowEnd = Ending row number with zero offset
nColEnd = Ending column number with zero offset
bInserNotDelete = false by default; if TRUE then insert rows
Return:
TRUE for success; otherwise FALSE
Example:
Worksheet wks("Data1");
ASSERT(wks.DeleteRange(1,1,3,2));
SeeAlso:
Worksheet::DeleteCol
*/
BOOL DeleteRange(int nRowBegin, int nColBegin, int nRowEnd, int nColEnd, BOOL bInsertNotDelete = false);
/**#
Retrieves the current selection from the worksheet.
Remarks:
This function is replaced by GetSelectedRange which follows a more consistent argument list of R1C1:R2C2. So this function is provided for
backward compatible reason only
*/
int GetSelection(int &c1, int &c2, int &r1, int &r2, string *pstrAddress = NULL);
/**
Retrieves the current selection from the worksheet.
Parameters:
r1 = on return it receives the index of the first row in the selection, if any
c1 = on return it receives the index of the first column in the selection, if any
r2 = on return it receives the index of the last row in the selection, if any
c2 = on return it receives the index of the last column in the selection, if any
pstrAddress = optional argument that will on return receive the address of the Excel selection range as string (assuming it is an Excel worksheet)
Return:
Integer indicating the type of selection. It can be a bitwise combination of one or more of the following:
WKS_SEL_NONE // no selection
WKS_SEL_EDIT // one cell being edited
WKS_SEL_COLUMN // one or more entire columns selected
WKS_SEL_ROW // one or more entire rows selected
WKS_SEL_RANGE // more than one cell selected
WKS_SEL_ONE_COL // exactly one column selected
WKS_SEL_DISCONTIGUOUS // discontiguous columns selected
WKS_SEL_ALL // entire worksheet
Example:
Worksheet wks("Data1");
int r1, c1,r2, c2;
string strAddress;
int seltype = wks.GetSelectedRange(r1, c1, r2, c2, &strAddress);
printf("sel = %d\tr1 = %d\tc1 = %d\tr2 = %d\tc2 = %d\n", seltype, r1, c1, r2, c2);
out_str(strAddress);
*/
int GetSelectedRange(int &r1, int &c1, int &r2, int &c2, string *pstrAddress = NULL);
/**
Remarks:
Retrieves the 0-offset indices of the selected columns in the worksheet.
Parameters:
v = vector of integers which will recieve the 0-offset indices of the selected columns
Return:
TRUE for success; otherwise FALSE
Example:
vector<int> v;
Worksheet wks("Data1");
BOOL bOK = wks.GetSelectedColumns(v);
*/
BOOL GetSelectedColumns(vector<int> &v);
/**
Remarks:
Updates the underlying Origin worksheet from Excel. This method is the equivalent of the combined Layer -s; and set %H -ui; LabTalk commands.
Parameters:
Return:
Returns TRUE on success and FALSE on failure.
Example:
Page pg("Book1");
Worksheet wks;
wks = (Worksheet)pg.Layers("Sheet1");
BOOL bOK = wks.UpdateOrigin();
*/
BOOL UpdateOrigin();
/**
Remarks:
Insert an empty column in the worksheet with the given name and store the name in a string.
If the given name already exists then increment it.
Parameters:
nPos = Column number with zero offset
lpcszColName = string to name inserted column
strColNameCreated = string to store the col name created
Return:
True for succesful; otherwise FALSE
Example:
Worksheet wks("Data1");
string ColName = "NewColoumn";
string ColNameCreated;
ASSERT(wks.InsertCol(1, ColName, ColNameCreated)); //Insert an empty column at the 1st column ( 0 offset)
printf("Column Name created is %s\n", ColNameCreated);
SeeAlso:
Worksheet::DeleteCol, Worksheet::InsertRow
*/
BOOL InsertCol(int nPos, LPCSTR lpcszColName, string &strColNameCreated);
/**
Remarks:
Get the value at the location (nRow, nCol) in the worksheet
Parameters:
nRow = Row number with zero offset
nCol = Column number with zero offset
Return:
Value at the location (nRow, nCol) in the worksheet
Example:
Worksheet wks("Data1");
wks.SetCell(0, 0, 3.14);
double cellValue = wks.Cell(0, 0);
printf("Value at (0,0) location is %f\n", cellValue);
SeeAlso:
Worksheet::GetCell, Worksheet::SetCell, Worksheet::TCell
*/
double Cell(int nRow, int nCol);
/**
Remarks:
Get the value at the location (nRow, nCol) in the worksheet as a string
Parameters:
nRow = Row number with zero offset
nCol = Column number with zero offset
strText = string to store the value
Return:
TRUE for success; otherwise FALSE.
Example:
Worksheet wks("Data1");
wks.SetCell(0, 0, 3.14);
string strText;
wks.GetCell(0, 0, strText);
printf("Value at (0,0) location is %s\n", strText);
SeeAlso:
Worksheet::Cell, Worksheet::SetCell, Worksheet::TCell
*/
BOOL GetCell(int nRow, int nCol, string& strText);
/**
Remarks:
Set the value at the location (nRow, nCol) in the worksheet as a string
Parameters:
nRow = Row number with zero offset
nCol = Column number with zero offset
lpcszText = string to be set to location (nRow, nCol)
Return:
TRUE for success; otherwise FALSE.
Example:
Worksheet wks("Data1");
string strText="Monday";
wks.SetCell(0, 0, strText);
string cellText;
wks.GetCell(0, 0, cellText);
printf("Value at (0,0) location is %s\n", cellText);
SeeAlso:
Worksheet::Cell, Worksheet::GetCell, Worksheet::TCell
*/
BOOL SetCell(int nRow, int nCol, LPCSTR lpcszText);
/**
Remarks:
Set the value at the location (nRow, nCol) in the worksheet
Parameters:
nRow = Row number with zero offset
nCol = Column number with zero offset
value = Value to set at the location (nRow, nCol)
Return:
TRUE for success; otherwise FALSE.
Example:
Worksheet wks("Data1");
double value = 1000.05;
wks.SetCell(0, 0, value);
double cellValue = wks.Cell(0, 0);
printf("Value at (0,0) location is %f\n", cellValue);
SeeAlso:
Worksheet::Cell, Worksheet::GetCell, Worksheet::TCell
*/
BOOL SetCell(int nRow, int nCol, double value);
/**
Remarks:
Get the value at the location (nRow, nCol) in the worksheet as a string
Parameters:
nRow = Row number with zero offset
nCol = Column number with zero offset
Return:
string at the location (nRow, nCol) in the worksheet
Example:
Worksheet wks("Data1");
string strText="Monday";
wks.SetCell(0, 0, strText);
string cellText = wks.TCell(0, 0);
printf("Value at (0,0) location is %s\n", cellText);
SeeAlso:
Worksheet::Cell, Worksheet::GetCell, Worksheet::SetCell
*/
string TCell(int nRow, int nCol);
#ifdef ORIGIN_COM_SUPPORT
/**
Put the data from an SPC blob into the worksheet.
Parameters:
varBlob = the VARIANT blob containing the data
nRow = Optional row number to begin the import at
nCol = Optional column number to begin the import at
nRepaintMode = Window Refresh mode
Return:
TRUE for success; otherwise FALSE
Example:
void blob_to_wks()
{
Object oSpcIO;
string strPathName = "E:\\myfile.spc";
// the GRAMS object used for importing the SPC file
oSpcIO = CreateObject("GSpcIOLib.GSpcIO");
oSpcIO.OpenFile(strPathName);
_VARIANT varBlob;
varBlob = oSpcIO.SaveBlob();
Worksheet wks("Data1");
BOOL bRet = wks.PutSPCBlob(varBlob);
out_int("Return value from PutSPCBlob is ", bRet);
}
Remarks:
This function is available only for OriginPro versions, or with a special COM enabled license
*/
BOOL PutSPCBlob(_VARIANT &varBlob,
int nRow = -1,
int nCol = 0,
int nRepaintMode = 0);
/**
Put the data from a recordset into the worksheet.
Remarks:
This function is available only for OriginPro versions, or with a special COM enabled license
Parameters:
objrs or varobjrs = the recordset
nRowBegin = the starting row in the worksheet
nNumRows = total number of records to retrieve,or -1 to retrieve all available.
nColBegin = it applies only to the options LAYWKGETRECORDSET_BY_COLUMN_INDEX with or without LAYWKGETRECORDSET_BY_COLUMN_INDEX and LAYWKGETRECORDSET_SET_COLUMN_NAME bits
the column in worksheet from which to begin.
nOptions = enum {
LAYWKGETRECORDSET_BY_COLUMN_INDEX = 0, // beginning with the starting column nColBegin retrieve all fields (will add columns as necessary)
LAYWKGETRECORDSET_BY_COLUMN_NAME = 2, // it retrieves only the data from those fields whose names match column names
LAYWKGETRECORDSET_BY_COLUMN_LABEL, // it retrieves only the data from those fields whose names match column labels
LAYWKGETRECORDSET_SET_COLUMN_NAME = 0x00010000, // used in conjunction with LAYWKGETRECORDSET_BY_COLUMN_INDEX to set column names to field names
LAYWKGETRECORDSET_SET_COLUMN_LABEL = 0x00020000, // used in conjunction with LAYWKGETRECORDSET_BY_COLUMN_INDEX to set column labels to field names
LAYWKGETRECORDSET_BY_COLUMN_INDEX_WITH_COLUMN_RENAMING = LAYWKGETRECORDSET_BY_COLUMN_INDEX | LAYWKGETRECORDSET_SET_COLUMN_NAME, // same as LAYWKGETRECORDSET_BY_COLUMN_INDEX, except that it will also rename all columns to the field names
};
Return:
TRUE for success; otherwise FALSE.
Example:
void recordset_to_worksheet()
{
Object ocrs;
ocrs = CreateObject("ADODB.Recordset");
ocrs.open("select * from customers", "Provider=SQLOLEDB; Data Source=myServer; Initial Catalog=northwind; User ID=myID; Password=myPassword;");
Worksheet wks("Data1");
// Put the recordset into worksheet:
BOOL bRet = wks.PutRecordset(ocrs, 0, -1, 0, LAYWKGETRECORDSET_BY_COLUMN_INDEX | LAYWKGETRECORDSET_SET_COLUMN_NAME);
out_int("bRet = ", bRet);
}
SeeAlso:
Worksheet::UpdateRecordset
*/
BOOL PutRecordset(Object &objrs,
int nRowBegin = 0,
int nNumRows = -1,
int nColBegin = 0,
int nOptions = LAYWKGETRECORDSET_BY_COLUMN_INDEX);
/**
Put the data from a recordset into the worksheet.
Remarks:
This function is available only for OriginPro versions, or with a special COM enabled license
Parameters:
objrs or varobjrs = the recordset
nRowBegin = the starting row in the worksheet
nNumRows = total number of records to retrieve,or -1 to retrieve all available.
nColBegin = it applies only to the options LAYWKGETRECORDSET_BY_COLUMN_INDEX and LAYWKGETRECORDSET_BY_COLUMN_INDEX_WITH_COLUMN_RENAMING
the column in worksheet from which to begin.
nOptions = enum {
LAYWKGETRECORDSET_BY_COLUMN_INDEX = 0, // beginning with the starting column nColBegin retrieve all fields (will add columns as necessary)
LAYWKGETRECORDSET_BY_COLUMN_NAME = 2, // it retrieves only the data from those fields whose names match column names
LAYWKGETRECORDSET_BY_COLUMN_LABEL, // it retrieves only the data from those fields whose names match column labels
LAYWKGETRECORDSET_SET_COLUMN_NAME = 0x00010000, // used in conjunction with LAYWKGETRECORDSET_BY_COLUMN_INDEX to set column names to field names
LAYWKGETRECORDSET_SET_COLUMN_LABEL = 0x00020000, // used in conjunction with LAYWKGETRECORDSET_BY_COLUMN_INDEX to set column labels to field names
LAYWKGETRECORDSET_BY_COLUMN_INDEX_WITH_COLUMN_RENAMING = LAYWKGETRECORDSET_BY_COLUMN_INDEX | LAYWKGETRECORDSET_SET_COLUMN_NAME, // same as LAYWKGETRECORDSET_BY_COLUMN_INDEX, except that it will also rename all columns to the field names
};
Return:
TRUE for success; otherwise FALSE.
Example:
void recordset_to_worksheet()
{
Object ocrs;
ocrs = CreateObject("ADODB.Recordset");
ocrs.open("select * from customers", "Provider=SQLOLEDB; Data Source=myServer; Initial Catalog=northwind; User ID=myID; Password=myPassword;");
Worksheet wks("Data1");
// Put the recordset into worksheet:
BOOL bRet = wks.PutRecordset(ocrs, 0, -1, 0, LAYWKGETRECORDSET_BY_COLUMN_INDEX | LAYWKGETRECORDSET_SET_COLUMN_LABEL);
out_int("bRet = ", bRet);
}
SeeAlso:
Worksheet::UpdateRecordset
*/
BOOL PutRecordset(_VARIANT &varobjrs,
int nRowBegin = 0,
int nNumRows = -1,
int nColBegin = 0,
int nOptions = LAYWKGETRECORDSET_BY_COLUMN_INDEX);
/**
Put the data from the worksheet into the recordset. The locktype of the recordset must be appropriate for
adding data which means that it should not be read-only.
Remarks:
This function is available only for OriginPro versions, or with a special COM enabled license
Parameters:
objrs or varobjrs = the recordset
nRowBegin = the starting row in the worksheet
nNumRows = total number of rows to put,or -1 to put all rows.
nColBegin = the worksheet column from which to start (the first column will be used for the first field, etc.).
nNumCols = the number of columns to use, beginning with nColBegin, or -1 to use all columns to the right of nColBegin.
If there are less columns than fields, the remaining fields will be set to null.
Return:
TRUE for success; otherwise FALSE.
Example:
void worksheet_recordset()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -