Здравствуйте!
Подскажите пожалуйста, как сохранить изменения в Exel документе. Создал такой класс:
class MyTableWidget : public QTableWidget
{
Q_OBJECT
public:
QTableWidgetItem *my_item;
QAxObject *excel;
QAxObject *workbooks;
QAxObject *workbook;
QAxObject *sheets;
QAxObject *sheet;
QAxObject *cell;
QAxObject *row;
MyTableWidget()
{
excel = new QAxObject("Excel.Application", this );
excel->dynamicCall("SetVisible(bool)", FALSE );
workbooks = excel->querySubObject("WorkBooks()");
workbooks->dynamicCall("Open (const QString&)", QString("C:/data1.xls"));
workbook = excel->querySubObject("ActiveWorkBook");
if (workbook) {
sheets = workbook->querySubObject("Sheets");
sheet = sheets->querySubObject("Item(1)");
sheet->dynamicCall("Select()");
connect(excel, SIGNAL(exception(int, QString, QString, QString)), SLOT(MYdebugError(int,QString,QString,QString)));
connect(workbooks, SIGNAL(exception(int, QString, QString, QString)), SLOT(MYdebugError(int,QString,QString,QString)));
connect(workbook, SIGNAL(exception(int, QString, QString, QString)), SLOT(MYdebugError(int,QString,QString,QString)));
connect(sheets, SIGNAL(exception(int, QString, QString, QString)), SLOT(MYdebugError(int,QString,QString,QString)));
connect(sheet, SIGNAL(exception(int, QString, QString, QString)), SLOT(MYdebugError(int,QString,QString,QString)));
int r = 0;
setColumnCount(4);
setRowCount(0);
QString v = "";
while(r >= 0)
{
for (int c=0; c<4 && r>=0; ++c)
{
cell = sheet->querySubObject("cells(int, int)", r+1, c+1 );
cell->dynamicCall("Select()");
if (cell) v = cell->property("Value").toString();
else v = "";
qDebug() << r << c << v;
if (c == 0 && r > 0)
{
if (v.length() != 0 && r < 10000)
{
insertRow(rowCount());
row = sheet->querySubObject("rows(int)", r+1 );
int points = row->property("Height").toInt();
int pixels = points * 1.2;
setRowHeight(r-1, pixels);
}
else r = -11111;
}
if (r >= 0)
{
my_item = new QTableWidgetItem(v);
if (r == 0)setHorizontalHeaderItem(c, my_item);
else setItem(r-1, c, my_item);
}
}
r++;
}
}
delete row;
connect(this, SIGNAL(itemChanged (QTableWidgetItem *)), SLOT (slot_itemChanged(QTableWidgetItem *)));
}
~MyTableWidget()
{
delete excel;
delete workbooks;
delete workbook;
delete sheets;
delete sheet;
delete cell;
}
public slots:
void MYdebugError(int errorCode, QString source, QString description, QString help)
{
qDebug() << errorCode << source << description << help;
}
void slot_itemChanged ( QTableWidgetItem * item )
{
cell = sheet->querySubObject("cells(int, int)", item->row()+2, item->column()+1 );
cell->dynamicCall("Select()");
cell->setProperty("Value", item->text());
workbook->dynamicCall("Save(void)");
}
};
необходимо, чтобы в слоте slot_itemChanged значение ячейки менялось. Сейчас вместо этого появляется окно с сообщением: "Файл "..." уже существует. ..."