首页 it专业术语大全

it专业术语大全

举报
开通vip

it专业术语大全it专业术语大全 #include "stdafx.h" #include "ReadWriteExcel.h" #include "ReadWriteExcelDlg.h" #include "DlgProxy.h" #include "afxdialogex.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CReadWriteExcelDlg dialog int Row, Line; CString Content; IMPLEMENT...

it专业术语大全
it专业术语大全 #include "stdafx.h" #include "ReadWriteExcel.h" #include "ReadWriteExcelDlg.h" #include "DlgProxy.h" #include "afxdialogex.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CReadWriteExcelDlg dialog int Row, Line; CString Content; IMPLEMENT_DYNAMIC(CReadWriteExcelDlg, CDialogEx); CReadWriteExcelDlg::CReadWriteExcelDlg(CWnd* pParent /*=NULL*/) : CDialogEx(CReadWriteExcelDlg::IDD, pParent) , m_line(_T("")) , m_row(_T("")) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_pAutoProxy = NULL; } CReadWriteExcelDlg::~CReadWriteExcelDlg() { // If there is an automation proxy for this dialog, set // its back pointer to this dialog to NULL, so it knows // the dialog has been deleted. if (m_pAutoProxy != NULL) m_pAutoProxy->m_pDialog = NULL; } void CReadWriteExcelDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Text(pDX, IDC_EDIT1, m_line); DDX_Text(pDX, IDC_EDIT2, m_row); DDX_Text(pDX, IDC_EDIT3, m_content); DDX_Control(pDX, IDC_LIST1, m_Grid); } BEGIN_MESSAGE_MAP(CReadWriteExcelDlg, CDialogEx) ON_WM_CLOSE() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_creat, &CReadWriteExcelDlg::OnBnClickedcreat) ON_BN_CLICKED(IDC_write, &CReadWriteExcelDlg::OnBnClickedwrite) ON_BN_CLICKED(IDC_read, &CReadWriteExcelDlg::OnBnClickedread) END_MESSAGE_MAP() // CReadWriteExcelDlg message handlers BOOL CReadWriteExcelDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here //设置列 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 视图的扩展风格 m_Grid.SetExtendedStyle(LVS_EX_FLATSB //扁平风格显 示滚动条 |LVS_EX_FULLROWSELECT //允许 整行选中 |LVS_EX_HEADERDRAGDROP //允许 整列拖动 |LVS_EX_ONECLICKACTIVATE //单击 选中项 |LVS_EX_GRIDLINES); //画出网格线 //设置表头 m_Grid.InsertColumn(0,_T("A"),LVCFMT_LEFT,50); m_Grid.InsertColumn(1,_T("B"),LVCFMT_LEFT,50); m_Grid.InsertColumn(2,_T("C"),LVCFMT_LEFT,50); m_Grid.InsertColumn(3,_T("D"),LVCFMT_LEFT,50); m_Grid.InsertColumn(4,_T("E"),LVCFMT_LEFT,50); m_Grid.InsertColumn(5,_T("F"),LVCFMT_LEFT,50); m_Grid.InsertColumn(6,_T("G"),LVCFMT_LEFT,50); m_Grid.InsertColumn(7,_T("H"),LVCFMT_LEFT,50); m_Grid.InsertColumn(8,_T("I"),LVCFMT_LEFT,50); m_Grid.InsertColumn(9,_T("J"),LVCFMT_LEFT,50); m_Grid.InsertColumn(10,_T("K"),LVCFMT_LEFT,50); m_Grid.InsertColumn(11,_T("L"),LVCFMT_LEFT,50); m_Grid.InsertColumn(12,_T("M"),LVCFMT_LEFT,50); m_Grid.InsertColumn(13,_T("N"),LVCFMT_LEFT,50); m_Grid.InsertColumn(14,_T("O"),LVCFMT_LEFT,50); m_Grid.InsertColumn(15,_T("P"),LVCFMT_LEFT,50); m_Grid.InsertColumn(16,_T("Q"),LVCFMT_LEFT,50); m_Grid.InsertColumn(17,_T("R"),LVCFMT_LEFT,50); // //向列表中插入数据 m_Grid.InsertItem(0,_T("")); m_Grid.InsertItem(1,_T("")); m_Grid.InsertItem(2,_T("")); m_Grid.InsertItem(3,_T("")); m_Grid.InsertItem(4,_T("")); m_Grid.InsertItem(5,_T("")); m_Grid.InsertItem(6,_T("")); m_Grid.InsertItem(7,_T("")); m_Grid.InsertItem(8,_T("")); m_Grid.InsertItem(9,_T("")); m_Grid.InsertItem(10,_T("")); m_Grid.InsertItem(11,_T("")); m_Grid.InsertItem(12,_T("")); m_Grid.InsertItem(13,_T("")); m_Grid.InsertItem(14,_T("")); m_Grid.InsertItem(15,_T("")); m_Grid.InsertItem(16,_T("")); m_Grid.InsertItem(17,_T("")); m_Grid.InsertItem(18,_T("")); m_Grid.InsertItem(19,_T("")); return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CReadWriteExcelDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialogEx::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CReadWriteExcelDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } // Automation servers should not exit when a user closes the UI // if a controller still holds on to one of its objects. These // message handlers make sure that if the proxy is still in use, // then the UI is hidden but the dialog remains around if it // is dismissed. void CReadWriteExcelDlg::OnClose() { if (CanExit()) CDialogEx::OnClose(); } void CReadWriteExcelDlg::OnOK() { if (CanExit()) CDialogEx::OnOK(); } void CReadWriteExcelDlg::OnCancel() { if (CanExit()) CDialogEx::OnCancel(); } BOOL CReadWriteExcelDlg::CanExit() { // If the proxy object is still around, then the automation // controller is still holding on to this application. Leave // the dialog around, but hide its UI. if (m_pAutoProxy != NULL) { ShowWindow(SW_HIDE); return FALSE; } return TRUE; } void CReadWriteExcelDlg::OnBnClickedcreat() { // TODO: Add your control notification handler code here //获得当前程序所在的路径,excel文件在此路径下。 char CurrentProgramPath[MAX_PATH]; GetCurrentDirectory(MAX_PATH,CurrentProgramPath); CString strFile = CurrentProgramPath;//ExcelFilePathName表示excel文件的路径和文件名 strFile += "\\Data.xlsx"; COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); HRESULT hr; hr = CoInitialize(NULL); if(FAILED(hr)) { AfxMessageBox(_T("Failed to call Coinitialize()" )); } CApplication app; CWorkbook book; CWorkbooks books; CWorksheet sheet; CWorksheets sheets; CRange range; CFont font; if (!app.CreateDispatch(_T("Excel.Application"))) { MessageBox(_T("Error!Creat Excel Application Server Faile!")); } books = app.get_Workbooks(); book = books.Add(covOptional); sheets=book.get_Worksheets(); sheet = sheets.get_Item(COleVariant((short)1)); //下面两行,是向A1中写入"Yeah!I can write data to excel!" range = sheet.get_Range(COleVariant(_T("A1")),COleVariant(_T("H1"))); range.put_Value2(COleVariant(_T("Yeah!"))); //设置列宽 range = sheet.get_Range(COleVariant(_T("A1")),COleVariant(_T("J1"))); range.put_ColumnWidth(_variant_t((long)5)); //显示表格 //app.put_Visible(TRUE); //保存 book.SaveCopyAs(COleVariant(strFile)); book.put_Saved(true); //结尾,释放 book.ReleaseDispatch(); books.ReleaseDispatch(); app.ReleaseDispatch(); app.Quit(); } void CReadWriteExcelDlg::OnBnClickedwrite() { // TODO: Add your control notification handler code here UpdateData(TRUE); if ((m_line.IsEmpty())||(m_row.IsEmpty())) { AfxMessageBox("行、列、内容不能为空~"); return; } Line = strtol(m_line,NULL,10); Row = strtol(m_row,NULL,10); if (17< Row || Row < 1 ) { AfxMessageBox("注意列的范围(1 - 17)"); return; } if (20< Line ||Line < 0) { AfxMessageBox("注意行的范围(1 - 20)"); return; } Content = m_content; m_CALL1(); } void CReadWriteExcelDlg::m_CALL1(void) { HRESULT hr; hr = CoInitialize(NULL); if(FAILED(hr)) { AfxMessageBox(_T("Failed to call Coinitialize()" )); } //声明操作excel文件类的对象 CApplication objApp; //组件服务器的各个classes //_application代表了EXCEL服务器 CWorkbooks objBooks;//workbooks表示整个Excel服务器(表现为一个.xls文件)里所有的表,(可以通过"新建"得到多个表,即MDI程序里的一个视窗一样,所有的视窗就是workbooks), CWorkbook objBook; //_workbook就是一个表,相当于MDI中的一个视窗, CWorksheets objSheets; // worksheets表示所有的表单,每个表都可能有很多表单(建立一个Excel文件之后,打开,可以看到有sheet1,sheet2等,所有这些sheetn就组成了worksheets) CWorksheet objSheet; //_worksheet就表示一个表单, CRange objRange,usedRange; //Range 表示元素的集合 LPDISPATCH lpDisp; //LPDISPATCH就是一个指向excel对象的指针 COleVariant VOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); //检测电脑上是否安装了Excel程序。 if(!objApp.CreateDispatch("Excel.Application")) //启动服务器 { AfxMessageBox("无法启动Excel服务器!"); return; } //获得当前程序所在的路径,excel文件在此路径下。 char CurrentProgramPath[MAX_PATH]; GetCurrentDirectory(MAX_PATH,CurrentProgramPath); CString ExcelFilePathName = CurrentProgramPath; //ExcelFilePathName表示 excel文件的路径和文件名 ExcelFilePathName += "\\Data.xlsx"; objBooks.AttachDispatch(objApp.get_Workbooks()); //此句的功能objBooks = objApp.GetWorkbooks();一样 //打开Excel文件,如果前面设置了objApp.SetVisible(TRUE),所以下句命 令执行后,显示这个excel文件的数据。 //如果前面没有设置objAppApp.SetVisible(TRUE),下句命令执行后,不会 显示这个Excel文件的数据。 lpDisp=objBooks.Open(ExcelFilePathName,VOptional,VOptional,VOptional,VO ptional,VOptional, VOptional,VOptional,VOptional,VOptional,VOptional,VOptional,VOptional,VO ptional,VOptional); objBook.AttachDispatch(lpDisp); //设定当前的工作表sheet objSheets.AttachDispatch(objBook.get_Worksheets()); lpDisp=objBook.get_ActiveSheet(); objSheet.AttachDispatch(lpDisp); //获取excel中的数据 objRange.AttachDispatch(objSheet.get_Cells()); //判断要输入的内容是否为空 if(m_content.IsEmpty()) { objRange.put_Item(COleVariant(long(Line)),COleVariant(long(Row)),COleVari ant()); AfxMessageBox("删除了该格内容~"); } //追加内容。 objRange.put_Item(COleVariant(long(Line)),COleVariant(long(Row)),COleVari ant(Content)); objBook.Save();//如果打开的这个excel文件被其它的进程已经打开了,此句 代码执行后,会出现提示是否保存的对话框。 ////如果打开的这个excel文件被其它的进程使用只读方式已经打开了,此句 代码执行后,不会出现提示是否保存的对话框 // objApp.SetAlertBeforeOverwriting(FALSE); //取消提示是否保存的对话框 // objApp.SetDisplayAlerts(FALSE);//取消提示是否保存的对话框 //把此文件另存为别的文件名。 // objBook.SaveAs(COleVariant(ExcelFilePathName),VOptional,VOptional, // VOptional,VOptional,VOptional,0,VOptional,VOptional,VOptional,VOptional,VOptiona l); objBook.Close(VOptional,COleVariant(ExcelFilePathName),VOptional); objBooks.Close(); objApp.Quit(); } void CReadWriteExcelDlg::OnBnClickedread() { // TODO: Add your control notification handler code here HRESULT hr; hr = CoInitialize(NULL); if(FAILED(hr)) { AfxMessageBox(_T("Failed to call Coinitialize()" )); } CApplication app; //_application代表了EXCEL服务器 CWorkbooks books;//workbooks表示整个Excel服务器(表现为一个.xls文件) 里所有的表,(可以通过"新建"得到多个表,即MDI程序里的一个视窗一样,所有的视 窗就是workbooks), CWorkbook book;//_workbook就是一个表,相当于MDI中的一个视窗, CWorksheets sheets; // worksheets表示所有的表单,每个表都可能有很多表单 (建立一个Excel文件之后,打开,可以看到有sheet1,sheet2等,所有这些sheetn就组成 了worksheets) CWorksheet sheet;//_worksheet就表示一个表单, CRange objRange,usedRange;//Range 表示元素的集合 COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); VARIANT ret; //检测电脑上是否安装了Excel程序。 if(!app.CreateDispatch("Excel.Application")) { AfxMessageBox("无法启动Excel服务器!"); return; } books = app.get_Workbooks(); //获得当前程序所在的路径,excel文件在此路径下。 char CurrentProgramPath[MAX_PATH]; GetCurrentDirectory(MAX_PATH,CurrentProgramPath); CString ExcelFilePathName = CurrentProgramPath;//ExcelFilePathName表示 excel文件的路径和文件名 ExcelFilePathName += "\\Data.xlsx"; book = books.Open(ExcelFilePathName,covOptional, _variant_t(true), covOptional,covOptional, covOptional, covOptional,covOptional, covOptional, covOptional, covOptional, covOptional, covOptional,covOptional,covOptional); sheets = book.get_Worksheets(); sheet = sheets.get_Item(COleVariant((short)1)); usedRange.AttachDispatch(sheet.get_UsedRange()); objRange.AttachDispatch(usedRange.get_Rows()); long iRowNum=objRange.get_Count();//已经使用的行数 objRange.AttachDispatch(usedRange.get_Columns()); long iColumnNum=objRange.get_Count();//已经使用的列数 //objRange = objSheet.GetRange(COleVariant("A1"), COleVariant("C1000")); ret = objRange.get_Value(covOptional); COleSafeArray sa(ret); long lNumRows; long lNumCols; sa.GetUBound(1, &lNumRows); sa.GetUBound(2, &lNumCols); long index[2]; VARIANT val; int row, column; for(row=1;row<=iRowNum;row++)//row表示行数 { for(column=1;column<=iColumnNum;column++)//c表示列数 { index[0]=row; index[1]=column; sa.GetElement(index, &val);//val类对象中包含取的row行、column列的内容 switch(val.vt) { case VT_R8: //数字 { CString cstr2=""; cstr2.Format("%1.0f",val.dblVal); m_Grid.SetItemText(row-1,column-1,_T(cstr2)); break; } case VT_BSTR: //文字 { CString cstr2=""; cstr2 = (CString)val.bstrVal; m_Grid.SetItemText(row-1,column-1,_T(cstr2)); break; } case VT_EMPTY: //表示此row行、column列的内容为空。 CString cstr2=""; m_Grid.SetItemText(row-1,column-1,_T(cstr2)); break; } } } //AfxMessageBox(cstr); book.Close(COleVariant((short)FALSE),covOptional,covOptional); app.Quit(); }
本文档为【it专业术语大全】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_153723
暂无简介~
格式:doc
大小:49KB
软件:Word
页数:19
分类:互联网
上传时间:2017-09-30
浏览量:65