Vali 晟怎么读读?

-- Email Verification: please verify your account email address. We sent you an email with a link that you need to click in order to confirm your address. Until you click that link, your membership will not be valid.的翻译:-验证电子邮件: 请确认您的帐户的电子邮件地址。我们向您发送一封电子邮件,您需要单击以确认您的地址的链接。单击该链接,直到您的成员资格不会有效。 什么意思?中文翻译英文,英文翻译中文,怎么说?
青云英语翻译
-- Email Verification: please verify your account email address. We sent you an email with a link that you need to click in order to confirm your address. Until you click that link, your membership will not be valid.
选择语言:从
罗马尼亚语
罗马尼亚语
- 电子邮件验证:请验证您的帐户电子邮件地址。我们向您发送一封电子邮件,以确认您的地址,你需要点击一个链接。直到你点击该链接,您的会员将不再有效。
-验证电子邮件: 请确认您的帐户的电子邮件地址。我们向您发送一封电子邮件,您需要单击以确认您的地址的链接。单击该链接,直到您的成员资格不会有效。
-- 电子邮件证明: 请核实您的帐户电子邮件。 我们送了您电子邮件以您需要点击为了证实您的地址的链接。 直到您点击那个链接,您的会员资格不会是合法的。
--电子邮件核查:请验证您帐户邮件地址。 我们给你一封电子邮件,其中一个链接,你需要单击以确认您的地址。 直到您单击该链接,您的会员将不会有效。
-验证电子邮件: 请确认您的帐户的电子邮件地址。我们向您发送一封电子邮件,您需要单击以确认您的地址的链接。单击该链接,直到您的成员资格不会有效。优惠券怎么说是ERROR : This gift card code is not valid
- 最大的美国主机论坛
优惠券怎么说是ERROR : This gift card code is not valid
我用自己原来的注册域名的用户名来买,怎么提示ERROR : This gift card code is not valid,不管用了吗
This gift card code is not valid 这个是提示礼券错误你是不是把优惠码输入到礼券里面了
相关知识等待您来回答
该问题来自:美国主机侦探提供最新的美国主机信息帮助用户选购合适的美国主机。旗下论坛是国内最大的海外主机交流论坛。外语领域专家C++里如何读写xls文件
具体如何使用可见“针对Excel表格文件操作的编程实现”于
/document/viewdoc/?id=693
只是下载的代码里有内存泄露现象。需要在个别地方加入e-&Delete();//下面的代码是已经更正过的。
以后需要读写xls文件可加入此头文件调用即可。据说缺点是:速度慢.写入数据都是字符串格式.后者是事实,前者不详。先存下以防哪天觉得读写多个csv文件烦了可以拿来用下。
// Class to read and write to Excel and text delimited
spreadsheet
// Created by Yap Chun Wei
// December 2001
// Version 1.1
// Updates: Fix bug in ReadRow() which prevent reading of
single column spreadsheet
// Modified by jingzhou xu
#ifndef CSPREADSHEET_H
#define CSPREADSHEET_H
#include &odbcinst.h&
#include &afxdb.h&
class CSpreadSheet
CSpreadSheet(CString File, CString SheetOrSeparator, bool
Backup = true); // Open spreadsheet for reading and writing
~CSpreadSheet(); // Perform some cleanup functions
bool AddHeaders(CStringArray &FieldNames, bool
replace = false); // Add header row to spreadsheet
bool DeleteSheet(); // Clear text delimited file content
bool DeleteSheet(CString SheetName); // Clear entire Excel
spreadsheet content. The sheet itself is not deleted
bool AddRow(CStringArray &RowValues, long row
= 0, bool replace = false); // Insert or replace a row into
spreadsheet. Default is add new row.&
bool AddCell(CString CellValue, CString column, long row = 0,
bool Auto = true); // Replace or add a cell into Excel spreadsheet
using header row or column alphabet. Default is add cell into new
row. Set Auto to false if want to force column to be used as header
bool AddCell(CString CellValue, short column, long row = 0);
// Replace or add a cell into spreadsheet using column number.
Default is add cell into new row.&
bool ReplaceRows(CStringArray &NewRowValues,
CStringArray &OldRowValues); // Search and replace
rows in Excel spreadsheet
bool ReadRow(CStringArray &RowValues, long row
= 0); // Read a row from spreadsheet. Default is read the next
bool ReadColumn(CStringArray &ColumnValues,
CString column, bool Auto = true); // Read a column from Excel
spreadsheet using header row or column alphabet. Set Auto to false
if want to force column to be used as header name
bool ReadColumn(CStringArray &ColumnValues,
short column); // Read a column from spreadsheet using column
bool ReadCell (CString &CellValue, CString
column, long row = 0, bool Auto = true); // Read a cell from Excel
spreadsheet using header row or column alphabet. Default is read
the next cell in next row. Set Auto to false if want to force
column to be used as header name
bool ReadCell (CString &CellValue, short
column, long row = 0); // Read a cell from spreadsheet using column
number. Default is read the next cell in next row.
void BeginTransaction(); // Begin transaction
bool Commit(); // Save changes to spreadsheet
bool RollBack(); // Undo changes to spreadsheet
bool Convert(CString SheetOrSeparator);
inline void GetFieldNames (CStringArray
&FieldNames) {FieldNames.RemoveAll();
FieldNames.Copy(m_aFieldNames);} // Get the header row from
spreadsheet
inline long GetTotalRows() {return m_dTotalR} // Get total
number of rows in &spreadsheet
inline short GetTotalColumns() {return m_dTotalC} //
Get total number of columns in &spreadsheet
inline long GetCurrentRow() {return m_dCurrentR} // Get the
currently selected row in &spreadsheet
inline bool GetBackupStatus() {return m_bB} // Get
status of backup. True if backup is successful, False if
spreadsheet is not backup
inline bool GetTransactionStatus() {return m_bT} //
Get status of Transaction. True if Transaction is started, False if
Transaction is not started or has error in starting
inline CString GetLastError() {return m_sLastE} // Get
last error message
bool Open(); // Open a text delimited file for reading or
void GetExcelDriver(); // Get the name of the Excel-ODBC
short CalculateColumnNumber(CString column, bool Auto); //
Convert Excel column in alphabet into column number
bool m_bA // Internal flag to denote newly created
spreadsheet or previously created spreadsheet
bool m_bB // Internal flag to denote status of
bool m_bE // Internal flag to denote whether file is
Excel spreadsheet or text delimited spreadsheet
bool m_bT // Internal flag to denote status of
Transaction
long m_dCurrentR // Index of current row, starting from
long m_dTotalR // Total number of rows in
spreadsheet
short m_dTotalC // Total number of columns in Excel
spreadsheet. Largest number of columns in text delimited
spreadsheet
CString m_sS // SQL statement to open Excel spreadsheet for
CString m_sD // DSN string to open Excel spreadsheet for
reading and writing
CString m_stempS // Temporary string for SQL statements or
for use by functions
CString m_stempS // Temporary string for use by
CString m_sSheetN // Sheet name of Excel spreadsheet
CString m_sExcelD // Name of Excel Driver
CString m_sF // Spreadsheet file name
CString m_sS // Separator in text delimited
spreadsheet
CString m_sLastE // Last error message
CStringArray m_atempA // Temporary array for use by
CStringArray m_aFieldN // Header row in spreadsheet
CStringArray m_aR // Content of all the rows in
spreadsheet
CDatabase *m_D // Database variable for Excel
spreadsheet
CRecordset *m_rS // Recordset for Excel spreadsheet
// Open spreadsheet for reading and writing
CSpreadSheet::CSpreadSheet(CString File, CString
SheetOrSeparator, bool Backup) :
m_Database(NULL), m_rSheet(NULL), m_sFile(File),
m_dTotalRows(0), m_dTotalColumns(0), m_dCurrentRow(1),
m_bAppend(false), m_bBackup(Backup),
m_bTransaction(false)
// Detect whether file is an Excel spreadsheet or a text
delimited file
m_stempString = m_sFile.Right(4);
m_stempString.MakeLower();
if (m_stempString == ".xls") // File is an Excel
spreadsheet
m_bExcel =
m_sSheetName = SheetOrS
m_sSeparator = ",;.?";
else // File is a text delimited file
m_bExcel =
m_sSeparator = SheetOrS
if (m_bExcel) // If file is an Excel spreadsheet
m_Database = new CD
GetExcelDriver();
m_sDsn.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s",
m_sExcelDriver, m_sFile, m_sFile);
if (Open())
if (m_bBackup)
if ((m_bBackup) &&
(m_bAppend))
CString tempSheetName = m_sSheetN
m_sSheetName = "CSpreadSheetBackup";
m_bAppend =
if (!Commit())
m_bBackup =
m_bAppend =
m_sSheetName = tempSheetN
m_dCurrentRow = 1;
else // if file is a text delimited file
if (Open())
if ((m_bBackup) &&
(m_bAppend))
m_stempString = m_sF
m_stempSql.Format("%s.bak", m_sFile);
m_sFile = m_stempS
if (!Commit())
m_bBackup =
m_sFile = m_stempS
// Perform some cleanup functions
CSpreadSheet::~CSpreadSheet()
if (m_Database != NULL)
m_Database-&Close();
delete m_D
// Add header row to spreadsheet
bool CSpreadSheet::AddHeaders(CStringArray
&FieldNames, bool replace)
if (m_bAppend) // Append to old Sheet
if (replace) // Replacing header row rather than adding new
if (!AddRow(FieldNames, 1, true))
if (ReadRow(m_atempArray, 1)) // Add new columns
if (m_bExcel)
// Check for duplicate header row field
for (int i = 0; i & FieldNames.GetSize();
for (int j = 0; j & m_atempArray.GetSize();
if (FieldNames.GetAt(i) == m_atempArray.GetAt(j))
m_sLastError.Format("Duplicate header row field:%s\n",
FieldNames.GetAt(i));
m_atempArray.Append(FieldNames);
if (!AddRow(m_atempArray, 1, true))
m_sLastError = "Problems with adding headers\n";
// Update largest number of columns if necessary
if (m_atempArray.GetSize() &
m_dTotalColumns)
m_dTotalColumns = m_atempArray.GetSize();
else // New Sheet
m_dTotalColumns = FieldNames.GetSize();
if (!AddRow(FieldNames, 1, true))
m_dTotalRows = 1;
// Clear text delimited file content
bool CSpreadSheet::DeleteSheet()
if (m_bExcel)
if (DeleteSheet(m_sSheetName))
m_sLastError = "Error deleting sheet\n";
m_aRows.RemoveAll();
m_aFieldNames.RemoveAll();
m_dTotalColumns = 0;
m_dTotalRows = 0;
if (!m_bTransaction)
m_bAppend = // Set flag to new sheet
// Clear entire Excel spreadsheet content. The sheet itself is
not deleted
bool CSpreadSheet::DeleteSheet(CString SheetName)
if (m_bExcel) // If file is an Excel spreadsheet
// Delete sheet
m_Database-&OpenEx(m_sDsn,
CDatabase::noOdbcDialog);
SheetName = "[" + SheetName + "$A1:IV65536]";
m_stempSql.Format ("DROP TABLE %s", SheetName);
m_Database-&ExecuteSQL(m_stempSql);
m_Database-&Close();
m_aRows.RemoveAll();
m_aFieldNames.RemoveAll();
m_dTotalColumns = 0;
m_dTotalRows = 0;
catch(CDBException *e)
m_sLastError = e-&m_strE
m_Database-&Close();
e-&Delete();//
else // if file is a text delimited file
return DeleteSheet();
// Insert or replace a row into
spreadsheet.&
// Default is add new row.
bool CSpreadSheet::AddRow(CStringArray
&RowValues, long row, bool replace)
long tempR
if (row == 1)
if (m_bExcel)&
// Check for duplicate header row field for Excel
spreadsheet
for (int i = 0; i & RowValues.GetSize();
for (int j = 0; j & RowValues.GetSize();
if ((i != j) &&
(RowValues.GetAt(i) == RowValues.GetAt(j)))
m_sLastError.Format("Duplicate header row field:%s\n",
RowValues.GetAt(i));
// Check for reduced header row columns
if (RowValues.GetSize() &
m_dTotalColumns)
m_sLastError = "Number of columns in new header row cannot be
less than the number of columns in previous header row";
m_dTotalColumns = RowValues.GetSize();
// Update header row
m_aFieldNames.RemoveAll();
m_aFieldNames.Copy(RowValues);
if (m_bExcel)
if (m_dTotalColumns == 0)
m_sLastError = "No header row. Add header row first\n";
if (m_bExcel) // For Excel spreadsheet
if (RowValues.GetSize() &
m_aFieldNames.GetSize())
m_sLastError = "Number of columns to be added cannot be
greater than the number of fields\n";
else // For text delimited spreadsheet
// Update largest number of columns if necessary
if (RowValues.GetSize() &
m_dTotalColumns)
m_dTotalColumns = RowValues.GetSize();
// Convert row values
m_stempString.Empty();
for (int i = 0; i & RowValues.GetSize();
if (i != RowValues.GetSize()-1) // Not last column
m_stempSql.Format("\"%s\"%s", RowValues.GetAt(i),
m_sSeparator);
m_stempString += m_stempS
else // Last column
m_stempSql.Format("\"%s\"", RowValues.GetAt(i));
m_stempString += m_stempS
if (row &= m_dTotalRows) // Not adding new
if (replace) // Replacing row
m_aRows.SetAt(row-1, m_stempString);
else // Inserting row
m_aRows.InsertAt(row-1, m_stempString);
m_dTotalRows++;
if (!m_bTransaction)
else // Adding new rows
// Insert null rows until specified row
m_dCurrentRow = m_dTotalR
m_stempSql.Empty();
CString nullS
for (int i = 1; i &= m_dTotalC
if (i != m_dTotalColumns)
if (m_bExcel)
nullString.Format("\" \"%s", m_sSeparator);
nullString.Format("\"\"%s", m_sSeparator);
m_stempSql += nullS
if (m_bExcel)
m_stempSql += "\" \"";
m_stempSql += "\"\"";
for (int j = m_dTotalRows + 1; j &
m_dCurrentRow++;
m_aRows.Add(m_stempSql);
tempRow = m_dCurrentR
m_dCurrentRow = m_dTotalR
// Insert new row
m_dCurrentRow++;
m_aRows.Add(m_stempString);
if (row & m_dTotalRows)
m_dTotalRows =
else if (!row)
m_dTotalRows = m_dCurrentR
m_dCurrentRow = tempR
if (!m_bTransaction)
// Replace or add a cell into Excel spreadsheet using header
row or column alphabet.&
// Default is add cell into new row.
// Set Auto to false if want to force column to be used as
header name
bool CSpreadSheet::AddCell(CString CellValue, CString column,
long row, bool Auto)
short columnIndex = CalculateColumnNumber(column, Auto);
if (columnIndex == 0)
if (AddCell(CellValue, columnIndex, row))
// Replace or add a cell into spreadsheet using column
// Default is add cell into new row.
bool CSpreadSheet::AddCell(CString CellValue, short column,
if (column == 0)
m_sLastError = "Column cannot be zero\n";
long tempR
if (m_bExcel) // For Excel spreadsheet
if (column & m_aFieldNames.GetSize() + 1)
m_sLastError = "Cell column to be added cannot be greater than
the number of fields\n";
else // For text delimited spreadsheet
// Update largest number of columns if necessary
if (column & m_dTotalColumns)
m_dTotalColumns =
if (row &= m_dTotalRows)
ReadRow(m_atempArray, row);
// Change desired row
m_atempArray.SetAtGrow(column-1, CellValue);
if (row == 1)
if (m_bExcel) // Check for duplicate header row field
for (int i = 0; i & m_atempArray.GetSize();
for (int j = 0; j & m_atempArray.GetSize();
if ((i != j) &&
(m_atempArray.GetAt(i) == m_atempArray.GetAt(j)))
m_sLastError.Format("Duplicate header row field:%s\n",
m_atempArray.GetAt(i));
// Update header row
m_aFieldNames.RemoveAll();
m_aFieldNames.Copy(m_atempArray);
if (!AddRow(m_atempArray, row, true))
if (!m_bTransaction)
// Insert null rows until specified row
m_dCurrentRow = m_dTotalR
m_stempSql.Empty();
CString nullS
for (int i = 1; i &= m_dTotalC
if (i != m_dTotalColumns)
if (m_bExcel)
nullString.Format("\" \"%s", m_sSeparator);
nullString.Format("\"\"%s", m_sSeparator);
m_stempSql += nullS
if (m_bExcel)
m_stempSql += "\" \"";
m_stempSql += "\"\"";
for (int j = m_dTotalRows + 1; j &
m_dCurrentRow++;
m_aRows.Add(m_stempSql);
tempRow = m_dCurrentR
m_dCurrentRow = m_dTotalR
// Insert cell
m_dCurrentRow++;
m_stempString.Empty();
for (int j = 1; j &= m_dTotalC
if (j != m_dTotalColumns) // Not last column
if (j != column)
if (m_bExcel)
m_stempSql.Format("\" \"%s", m_sSeparator);
m_stempSql.Format("\"\"%s", m_sSeparator);
m_stempString += m_stempS
m_stempSql.Format("\"%s\"%s", CellValue, m_sSeparator);
m_stempString += m_stempS
else // Last column
if (j != column)
if (m_bExcel)
m_stempString += "\" \"";
m_stempString += "\"\"";
m_stempSql.Format("\"%s\"", CellValue);
m_stempString += m_stempS
m_aRows.Add(m_stempString);
if (row & m_dTotalRows)
m_dTotalRows =
else if (!row)
m_dTotalRows = m_dCurrentR
m_dCurrentRow = tempR
if (!m_bTransaction)
// Search and replace rows in Excel spreadsheet
bool CSpreadSheet::ReplaceRows(CStringArray
&NewRowValues, CStringArray
&OldRowValues)
if (m_bExcel) // If file is an Excel spreadsheet
m_Database-&OpenEx(m_sDsn,
CDatabase::noOdbcDialog);
m_stempSql.Format("UPDATE [%s] SET ", m_sSheetName);
for (int i = 0; i & NewRowValues.GetSize();
m_stempString.Format("[%s]='%s', ", m_aFieldNames.GetAt(i),
NewRowValues.GetAt(i));
m_stempSql = m_stempSql + m_stempS
m_stempSql.Delete(m_stempSql.GetLength()-2, 2);
m_stempSql = m_stempSql + " WHERE (";
for (int j = 0; j & OldRowValues.GetSize()-1;
m_stempString.Format("[%s]='%s' AND ", m_aFieldNames.GetAt(j),
OldRowValues.GetAt(j));
m_stempSql = m_stempSql + m_stempS
m_stempSql.Delete(m_stempSql.GetLength()-4, 5);
m_stempSql += ")";
m_Database-&ExecuteSQL(m_stempSql);
m_Database-&Close();
catch(CDBException *e)
m_sLastError = e-&m_strE
m_Database-&Close();
e-&Delete();
else // if file is a text delimited file
m_sLastError = "Function not available for text delimited
// Read a row from spreadsheet.&
// Default is read the next row
bool CSpreadSheet::ReadRow(CStringArray
&RowValues, long row)
// Check if row entered is more than number of rows in
if (row &= m_aRows.GetSize())
if (row != 0)
m_dCurrentRow =
else if (m_dCurrentRow &
m_aRows.GetSize())
// Read the desired row
RowValues.RemoveAll();
m_stempString = m_aRows.GetAt(m_dCurrentRow-1);
m_dCurrentRow++;
// Search for separator to split row
int separatorP
m_stempSql.Format("\"%s\"", m_sSeparator);
separatorPosition = m_stempString.Find(m_stempSql); // If
separator is "?"
if (separatorPosition != -1)
// Save columns
int nCount = 0;
int stringStartingPosition = 0;
while (separatorPosition != -1)
nCount = separatorPosition - stringStartingP
RowValues.Add(m_stempString.Mid(stringStartingPosition,
stringStartingPosition = separatorPosition +
m_stempSql.GetLength();
separatorPosition = m_stempString.Find(m_stempSql,
stringStartingPosition);
nCount = m_stempString.GetLength() -
stringStartingP
RowValues.Add(m_stempString.Mid(stringStartingPosition,
// Remove quotes from first column
m_stempString = RowValues.GetAt(0);
m_stempString.Delete(0, 1);
RowValues.SetAt(0, m_stempString);
// Remove quotes from last column
m_stempString = RowValues.GetAt(RowValues.GetSize()-1);
m_stempString.Delete(m_stempString.GetLength()-1, 1);
RowValues.SetAt(RowValues.GetSize()-1, m_stempString);
// Save columns
separatorPosition = m_stempString.Find(m_sSeparator); // if
separator is ?
if (separatorPosition != -1)
int nCount = 0;
int stringStartingPosition = 0;
while (separatorPosition != -1)
nCount = separatorPosition - stringStartingP
RowValues.Add(m_stempString.Mid(stringStartingPosition,
stringStartingPosition = separatorPosition +
m_sSeparator.GetLength();
separatorPosition = m_stempString.Find(m_sSeparator,
stringStartingPosition);
nCount = m_stempString.GetLength() -
stringStartingP
RowValues.Add(m_stempString.Mid(stringStartingPosition,
else // Treat spreadsheet as having one column
// Remove opening and ending quotes if any
int quoteBegPos = m_stempString.Find('\"');
int quoteEndPos = m_stempString.ReverseFind('\"');
if ((quoteBegPos == 0) &&
(quoteEndPos == m_stempString.GetLength()-1))
m_stempString.Delete(0, 1);
m_stempString.Delete(m_stempString.GetLength()-1, 1);
RowValues.Add(m_stempString);
m_sLastError = "Desired row is greater than total number of
rows in spreadsheet\n";
// Read a column from Excel spreadsheet using header row or
column alphabet.&
// Set Auto to false if want to force column to be used as
header name
bool CSpreadSheet::ReadColumn(CStringArray
&ColumnValues, CString column, bool Auto)
short columnIndex = CalculateColumnNumber(column, Auto);
if (columnIndex == 0)
if (ReadColumn(ColumnValues, columnIndex))
// Read a column from spreadsheet using column number
bool CSpreadSheet::ReadColumn(CStringArray
&ColumnValues, short column)
if (column == 0)
m_sLastError = "Column cannot be zero\n";
int tempRow = m_dCurrentR
m_dCurrentRow = 1;
ColumnValues.RemoveAll();
for (int i = 1; i &= m_aRows.GetSize();
// Read each row
if (ReadRow(m_atempArray, i))
// Get value of cell in desired column
if (column &= m_atempArray.GetSize())
ColumnValues.Add(m_atempArray.GetAt(column-1));
ColumnValues.Add("");
m_dCurrentRow = tempR
m_sLastError = "Error reading row\n";
m_dCurrentRow = tempR
// Read a cell from Excel spreadsheet using header row or
column alphabet.&
// Default is read the next cell in next
// Set Auto to false if want to force column to be used as
header name
bool CSpreadSheet::ReadCell (CString
&CellValue, CString column, long row, bool
short columnIndex = CalculateColumnNumber(column, Auto);
if (columnIndex == 0)
if (ReadCell(CellValue, columnIndex, row))
// Read a cell from spreadsheet using column
// Default is read the next cell in next row.
bool CSpreadSheet::ReadCell (CString
&CellValue, short column, long row)
if (column == 0)
m_sLastError = "Column cannot be zero\n";
int tempRow = m_dCurrentR
m_dCurrentRow =
if (ReadRow(m_atempArray, m_dCurrentRow))
// Get value of cell in desired column
if (column &= m_atempArray.GetSize())
CellValue = m_atempArray.GetAt(column-1);
CellValue.Empty();
m_dCurrentRow = tempR
m_dCurrentRow = tempR
m_dCurrentRow = tempR
m_sLastError = "Error reading row\n";
// Begin transaction
void CSpreadSheet::BeginTransaction()
m_bTransaction =
// Save changes to spreadsheet
bool CSpreadSheet::Commit()
if (m_bExcel) // If file is an Excel spreadsheet
m_Database-&OpenEx(m_sDsn,
CDatabase::noOdbcDialog);
if (m_bAppend)
// Delete old sheet if it exists
m_stempString= "[" + m_sSheetName + "$A1:IV65536]";
m_stempSql.Format ("DROP TABLE %s", m_stempString);
m_Database-&ExecuteSQL(m_stempSql);
catch(CDBException *e)
m_sLastError = e-&m_strE
m_Database-&Close();
e-&Delete();
// Create new sheet
m_stempSql.Format("CREATE TABLE [%s$A1:IV65536] (",
m_sSheetName);
for (int j = 0; j & m_aFieldNames.GetSize();
m_stempSql = m_stempSql + "[" + m_aFieldNames.GetAt(j) +"]" +
" char(255), ";
m_stempSql.Delete(m_stempSql.GetLength()-2, 2);
m_stempSql += ")";
// Create new sheet
m_stempSql.Format("CREATE TABLE [%s] (", m_sSheetName);
for (int i = 0; i & m_aFieldNames.GetSize();
m_stempSql = m_stempSql + "[" + m_aFieldNames.GetAt(i) +"]" +
" char(255), ";
m_stempSql.Delete(m_stempSql.GetLength()-2, 2);
m_stempSql += ")";
m_Database-&ExecuteSQL(m_stempSql);
if (!m_bAppend)
m_dTotalColumns = m_aFieldNames.GetSize();
m_bAppend =
catch(CDBException *e)
m_sLastError = e-&m_strE
m_Database-&Close();
e-&Delete();
// Save changed data
for (int k = 1; k & m_dTotalR k++)
ReadRow(m_atempArray, k+1);
// Create Insert SQL
m_stempSql.Format("INSERT INTO [%s$A1:IV%d] (", m_sSheetName,
for (int i = 0; i & m_atempArray.GetSize();
m_stempString.Format("[%s], ", m_aFieldNames.GetAt(i));
m_stempSql = m_stempSql + m_stempS
m_stempSql.Delete(m_stempSql.GetLength()-2, 2);
m_stempSql += ") VALUES (";
for (int j = 0; j & m_atempArray.GetSize();
m_stempString.Format("'%s', ", m_atempArray.GetAt(j));
m_stempSql = m_stempSql + m_stempS
m_stempSql.Delete(m_stempSql.GetLength()-2, 2);
m_stempSql += ")";
// Add row
m_Database-&ExecuteSQL(m_stempSql);
catch(CDBException *e)
m_sLastError = e-&m_strE
m_Database-&Close();
e-&Delete();
m_Database-&Close();
m_bTransaction =
else // if file is a text delimited file
CFile *File = NULL;
File = new CFile(m_sFile, CFile::modeCreate | CFile::modeWrite
&| CFile::shareDenyNone);
if (File != NULL)
CArchive *Archive = NULL;
Archive = new CArchive(File, CArchive::store);
if (Archive != NULL)
for (int i = 0; i & m_aRows.GetSize();
Archive-&WriteString(m_aRows.GetAt(i));
Archive-&WriteString("\r\n");
m_bTransaction =
catch(...)
m_sLastError = "Error writing file\n";
// Undo changes to spreadsheet
bool CSpreadSheet::RollBack()
if (Open())
m_bTransaction =
m_sLastError = "Error in returning to previous state\n";
bool CSpreadSheet::Convert(CString SheetOrSeparator)
// Prepare file
m_stempString = m_sF
m_stempString.Delete(m_stempString.GetLength()-4, 4);
if (m_bExcel) // If file is an Excel spreadsheet
m_stempString += ".csv";
CSpreadSheet tempSheet(m_stempString, SheetOrSeparator,
// Stop convert if text delimited file exists
if (tempSheet.GetTotalColumns() != 0)
tempSheet.BeginTransaction();
for (int i = 1; i &= m_dTotalR i++)
if (!ReadRow(m_atempArray, i))
if (!tempSheet.AddRow(m_atempArray, i))
if (!mit())
else // if file is a text delimited file
m_stempString += ".xls";
CSpreadSheet tempSheet(m_stempString, SheetOrSeparator,
// Stop convert if Excel file exists
if (tempSheet.GetTotalColumns() != 0)
GetFieldNames(m_atempArray);
// Check for duplicate header row field
bool duplicate =
for (int i = 0; i & m_atempArray.GetSize();
for (int j = 0; j & m_atempArray.GetSize();
if ((i != j) &&
(m_atempArray.GetAt(i) == m_atempArray.GetAt(j)))
m_sLastError.Format("Duplicate header row field:%s\n",
m_atempArray.GetAt(i));
duplicate =
if (duplicate) // Create dummy header row
m_atempArray.RemoveAll();
for (int k = 1; k &= m_dTotalC
m_stempString.Format("%d", k);
m_atempArray.Add(m_stempString);
if (!tempSheet.AddHeaders(m_atempArray))
for (int l = 1; l &= m_dTotalR l++)
if (!ReadRow(m_atempArray, l))
if (!tempSheet.AddRow(m_atempArray, l+1))
if (!tempSheet.AddHeaders(m_atempArray))
for (int l = 2; l &= m_dTotalR l++)
if (!ReadRow(m_atempArray, l))
if (!tempSheet.AddRow(m_atempArray, l))
// Open a text delimited file for reading or writing
bool CSpreadSheet::Open()
if (m_bExcel) // If file is an Excel spreadsheet
m_Database-&OpenEx(m_sDsn,
CDatabase::noOdbcDialog);
// Open Sheet
m_rSheet = new CRecordset( m_Database );
m_sSql.Format("SELECT * FROM [%s$A1:IV65536]",
m_sSheetName);
m_rSheet-&Open(CRecordset::forwardOnly, m_sSql,
CRecordset::readOnly);
catch(...)
delete m_rS
m_rSheet = NULL;
m_Database-&Close();
// Get number of columns
m_dTotalColumns =
m_rSheet-&m_nResultC
if (m_dTotalColumns != 0)
m_aRows.RemoveAll();
m_stempString.Empty();
m_bAppend =
m_dTotalRows++; // Keep count of total number of rows
// Get field names i.e header row
for (int i = 0; i & m_dTotalC i++)
m_stempSql =
m_rSheet-&m_rgODBCFieldInfos[i].m_strN
m_aFieldNames.Add(m_stempSql);
// Join up all the columns into a string
if (i != m_dTotalColumns-1) // Not last column
m_stempString = m_stempString + "\"" + m_stempSql + "\"" +
else // Last column
m_stempString = m_stempString + "\"" + m_stempSql +
// Store the header row as the first row in memory
m_aRows.Add(m_stempString);
// Read and store the rest of the rows in memory
while (!m_rSheet-&IsEOF())
m_dTotalRows++; // Keep count of total number of rows
// Get all the columns in a row
m_stempString.Empty();
for (short column = 0; column &
m_dTotalC column++)
m_rSheet-&GetFieldValue(column,
m_stempSql);
// Join up all the columns into a string
if (column != m_dTotalColumns-1) // Not last column
m_stempString = m_stempString + "\"" + m_stempSql + "\"" +
else // Last column
m_stempString = m_stempString + "\"" + m_stempSql +
// Store the obtained row in memory
m_aRows.Add(m_stempString);
m_rSheet-&MoveNext();
catch (...)
m_sLastError = "Error reading row\n";
delete m_rS
m_rSheet = NULL;
m_Database-&Close();
m_rSheet-&Close();
delete m_rS
m_rSheet = NULL;
m_Database-&Close();
m_dCurrentRow = 1;
else // if file is a text delimited file
CFile *File = NULL;
File = new CFile(m_sFile, CFile::modeRead |
CFile::shareDenyNone);
if (File != NULL)
CArchive *Archive = NULL;
Archive = new CArchive(File, CArchive::load);
if (Archive != NULL)
m_aRows.RemoveAll();
// Read and store all rows in memory
while(Archive-&ReadString(m_stempString))
m_aRows.Add(m_stempString);
ReadRow(m_aFieldNames, 1); // Get field names i.e header
// Get total number of rows
m_dTotalRows = m_aRows.GetSize();
// Get the largest number of columns
for (int i = 0; i & m_aRows.GetSize();
ReadRow(m_atempArray, i);
if (m_atempArray.GetSize() &
m_dTotalColumns)
m_dTotalColumns = m_atempArray.GetSize();
if (m_dTotalColumns != 0)
m_bAppend =
catch(...)
m_sLastError = "Error in opening file\n";
// Convert Excel column in alphabet into column number
short CSpreadSheet::CalculateColumnNumber(CString column, bool
int firstLetter, secondL
column.MakeUpper();
if (column.GetLength() == 1)
firstLetter = column.GetAt(0);
return (firstLetter - 65 + 1); // 65 is A in ascii
else if (column.GetLength() == 2)
firstLetter = column.GetAt(0);
secondLetter = column.GetAt(1);
return ((firstLetter - 65 + 1)*26 + (secondLetter - 65 + 1));
// 65 is A in ascii
// Check if it is a valid field name
for (int i = 0; i & m_aFieldNames.GetSize();
if (!pare(m_aFieldNames.GetAt(i)))
return (i + 1);
m_sLastError = "Invalid field name or column
alphabet\n";
// Get the name of the Excel-ODBC driver
void CSpreadSheet::GetExcelDriver()
char szBuf[2001];
WORD cbBufMax = 2000;
WORD cbBufO
char *pszBuf = szB
// Get the names of the installed drivers ("odbcinst.h" has to
be included )
if(!SQLGetInstalledDrivers(szBuf,cbBufMax,&
cbBufOut))
m_sExcelDriver = "";
// Search for the driver...
if( strstr( pszBuf, "Excel" ) != 0 )
// Found !
m_sExcelDriver = CString( pszBuf );
pszBuf = strchr( pszBuf, '\0' ) + 1;
while( pszBuf[1] != '\0' );
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 晟怎么读 的文章

 

随机推荐