⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 实现手机阅读EXCEL文件
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "vcl\utilcls.h"
#include "Unit1.h"
#include "Excel_2K_SRVR.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
 #define   PG   OlePropertyGet
           #define   PS   OlePropertySet
           #define   FN   OleFunction
           #define   PR   OleProcedure

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 String sql_text111="select * from QQ ";
                                      ADOQuery2->Close();
                                       ADOQuery2->SQL->Clear();
                                      ADOQuery2->SQL->Add(sql_text111);
                                   //   ADOQuery2->Prepare();
                                       ADOQuery2->Open();
                                      if( !ADOQuery2->Eof)
                                      {
                                      String  ee=ADOQuery2->FieldByName("q")->AsString;
                                      Edit1->Text=ee;


                                       ShowMessage("你好");



                                      }


}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
      Table1->Open();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
 Variant Ex,Wb,Sh1;
   //  Ex=Variant::CreateObject("Excel.Application");        //第一步,建对象
   try
{
    Ex = Variant::CreateObject ("Excel.Application");
}
catch(...)
{
    ShowMessage("运行Excel出错,请确认安装了Office");
    return;
}
     String  eew=GetCurrentDir()+"\\book1.xls";
     Ex.PG("WorkBooks").PR("Open",eew.c_str());          //第二步,打开工作薄
     Wb=Ex.PG("ActiveWorkBook");
     Sh1=Wb.PG("ActiveSheet");
     int nSheetCount=Wb.PG("Sheets").PG("Count");           //表数
    //   String wang=IntToStr(nSheetCount);
        Edit2->Text = nSheetCount;
      int www=Sh1.PG("UsedRange").PG("Columns").PG("Count"); //列数
     int eee=Sh1.PG("UsedRange").PG("Rows").PG("Count");    //行数

   //     for(int j=1;j<1000;j++)
    //    {
    //       Sh1.PG("Cells",j,2).PS("Value", j);

    //    }
   // Application->MessageBox("成功完成报表保存!\n可以按\'打开Excel文件\'按钮进行报表工作","提示",MB_ICONINFORMATION|MB_OK);
     for(int i=1;i<=eee;i++)
     {
        String guang=Sh1.PG("Cells",i,2).PG("Value");
        if(guang=="10")
        {
           String nihao=Sh1.PG("Cells",i,3).PG("Value");
      //   Edit7->Text =nihao.c_str();
      //   ShowMessage("ok");
         return;
        }


     }
       Edit3->Text=www;
        Edit4->Text=eee;
           Sh1.PG("Rows",2).PR("Insert",46);
     Wb.PG("Sheets", 1).PR("Select");
   //     Sh1.PG("Cells",4,5).PS("Value",1000);
         Sh1.PG("Rows", 2).PR("Delete"); //将第2行删除
       Sh1 = Wb.PG("ActiveSheet");
//第三步,定义为活跃
//   Ex.PS("StatusBar", "您好,请您稍等。正在查询!");
     Edit1->Text=Sh1.PG("Cells",1,1).PG("Value");            //第四步,定位单元格并获得数据
   //  for (int i=1;i<=100;i++)
    //    for (int j=1;j<=100;j++)
    //       Sh1.PG("Cells",i,j).PS("Value",i*100+j);
     String strValue = "abcdefg";
       Sh1.PG("Cells", 3, 6).PS("Value", strValue.c_str());        //写入数据
       //  Sh1.PG("Columns",1).PS("Value", 1234);
          String strValue2 = Sh1.PG("Cells", 3, 1).PG("Value");    //读取数据
          if(strValue2=="3")
          {
     //      ShowMessage("ddd");
          }
         // Edit5->Text=strValue2.c_str();
     //   String   shname="2";
     //     Edit6->Text=Sh1.PG("2",shname.c_str());
     //    Variant ExcelApp;
     //  ExcelApp = Variant::CreateObject ("Excel.Application");
  //   Wb.FN("Save");
        Sh1.PG("Rows", 2).PR("Delete");                          //将第2行删除

       Wb.FN("Save");
  //  Wb.FN("SaveAs", "c:\\book4.xls");//                     //保存为指定的文件
        Wb.PR("Close");
     //   Wb.FN("Close");//关闭表格
     //   Ex.FN("Close");
          Ex.FN ("Quit");
       Ex = Unassigned;
    //    Wb.OleProcedure("Save");
    //    Wb.OleProcedure("Close");
    //    Ex.OleFunction("Quit");
     //      ExcelApp.PG("workbooks").FN("Add");      //默认工作簿
    //   ExcelApp.PG("workbooks").FN("Add", 1);   //单工作表
     //  ExcelApp.PG("workbooks").FN("Add", 2);   //图表
     //  ExcelApp.PG("workbooks").FN("Add", 3);   //宏表
     //  ExcelApp.PG("workbooks").FN("Add", 4) ;  //国际通用宏表
    //   ExcelApp.PG("workbooks").FN("Add", 5) ;  //与默认的相同
    //   ExcelApp.PG("workbooks").FN("Add", 6) ;  //工作簿且只有一个表
     //   ExcelApp.PG("workbooks").FN("Add", "C:\\result.xlt");
       //   Range.PG("Cells").PS("Value", 10);
   //  Wb.PR("Save"); Wb.PR("Close");
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -