cell 导出excel 为什么没有表头
vb.net 用ExportExcelDlg 函数导出excel没有表头(即列标题) 自己搞定了哎,以下代码可以把标题带出Try
Dim nRows As Long, nCols As Long, nCurSheet As Integer, i As Long
Dim StrCell As String
nCurSheet = Cell2.GetCurSheet()
nCols = Cell2.GetCols(nCurSheet)
Cell2.InsertRow(1, 1, nCurSheet)
For i = 1 To nCols - 1
StrCell = Cell2.GetCellString(i, 0, nCurSheet)
Cell2.SetCellString(i, 1, 0, StrCell)
Next
Cell2.WorkbookReadonly = False'防止导出excel后提示只读
Cell2.ExportExcelDlg()
Finally
Cell2.WorkbookReadonly = True
Cell2.DeleteRow(1, 1, 0)
End Try 高手必须顶起啊,但是……不会弄啊,能写个工具吗! 很简单
m_pGrid就是cell 这个 组件的 变量 那么它当中可以调用的函数 都是一样的
我用 c++解释一遍就好了
//获取当前页签
int nSheet = m_pGrid->GetCurSheet();
if(nSheet == -1)
return;
//通过当前页签获取当前多少列
int nCols= m_pGrid->GetCols(nSheet);
if(nCols == 0)
return;
//然后在当前页签插入一列
m_pGrid->InsertRow(1, 1, nSheet);
for(int i = 0; i < nCols; i ++)
{
//获取到每一列的列头名
QString str = m_pGrid->GetCellString(i,0,nSheet);
//将列头设置到插入的列中
m_pGrid->SetCellString(i,1,nSheet,str);
}
//设置导出excel为可编辑
m_pGrid->SetWorkbookReadonly(false);
//然后导出成excel
int n = m_pGrid->ExportExcelDlg();
//设置excel为不可编辑
m_pGrid->SetWorkbookReadonly(true);
//最后删除插入的列
m_pGrid->DeleteRow(0,1,nSheet);
页:
[1]