我可以控制某一单元格的边框是否显示但不能只让其只显示某几边!!!

解决方案 »

  1.   

    //这是我利用excel中的宏编辑的数据倒入excel中的一个例子,希望有帮助。
    procedure TForm_ejjgs.BitBtn8Click(Sender: TObject);
    var
           excel,workbook:variant;
           xlsfilename:string;
           i,j:integer;
            begin         try
               excel:=createoleobject('excel.application');
               workbook:=createoleobject('excel.sheet');         except
                 showmessage('您的机器里未安装Microsoft excel');
              end;
            try
              excel:=createoleobject('excel.application');
              excel.workbooks.open('c:\gcsgl\demo.xls');
              xlsfilename:='demo.xls';
              excel.worksheets[4].activate;
             //ClearContents
              excel.activeSheet.Name:= '二级注册结构师';
              //给单元格赋值。
               Data.ADOQuery_gcsgl.First;
               j:=data.adoquery_gcsgl.recordcount;
               //['a2:h'+InttoStr(j+2)].ClearContents;
               excel.activesheet.range['a2:h1000'].ClearContents;
               for i:=1 to  Data.ADOQuery_gcsgl.RecordCount do
               begin
                excel.Cells(i+2,1):=Data.ADOQuery_gcsgl.FieldByName('序号').asstring;
                excel.Cells(i+2,2):=Data.ADOQuery_gcsgl.FieldByName('姓名').asstring;
                excel.Cells(i+2,3):=Data.ADOQuery_gcsgl.FieldByName('注册单位').asstring;
                excel.Cells(i+2,4):=trim(Data.ADOQuery_gcsgl.FieldByName('身份证号').asstring);
                excel.Cells(i+2,5):=Data.ADOQuery_gcsgl.FieldByName('执业印章号').asstring;
                excel.Cells(i+2,6):=Data.ADOQuery_gcsgl.FieldByName('注册证书号').asstring;
                excel.Cells(i+2,7):=Data.ADOQuery_gcsgl.FieldByName('截止日期').asstring;
                excel.Cells(i+2,8):=Data.ADOQuery_gcsgl.FieldByName('备注').asstring;
                 excel.activesheet.rows[i+2].rowheight:=20;
                Data.ADOQuery_gcsgl.MoveBy(1);
               end;
                 //格式
                  excel.activesheet.range['a1:h1'].font.FontStyle:='粗体';
                  excel.activesheet.range['a1:h1'].HorizontalAlignment := xlCenter;
                  excel.activesheet.range['a1:h1'].VerticalAlignment:= xlCenter;
                  excel.activesheet.range['a1:h1'].ReadingOrder := xlContext;
                  excel.activesheet.range['a1:h1'].MergeCells := True;
                  excel.activesheet.range['a2:h2'].font.FontStyle:='粗体';
                  excel.cells[1,1].value:='甘 肃 省 二 级 注 册 结 构 师 名 单';
                  excel.ActiveSheet.PageSetup.TopMargin :=2.8/0.035;
                 //列宽
                excel.activesheet.columns[1].columnwidth:=6;
                excel.activesheet.columns[2].columnwidth:=6;
                excel.activesheet.columns[3].columnwidth:=30;
                excel.activesheet.columns[4].columnwidth:=20;
                excel.activesheet.columns[5].columnwidth:=15;
                excel.activesheet.columns[6].columnwidth:=15;
                excel.activesheet.columns[7].columnwidth:=10;
                excel.activesheet.columns[8].columnwidth:=20;
                excel.cells[2,1].value:='序号';
                excel.cells[2,2].value:='姓名';
                excel.cells[2,3].value:='注册单位';
                excel.cells[2,4].value:='身份证号';
                excel.cells[2,5].value:='执业印章号';
                excel.cells[2,6].value:='注册证书号';
                excel.cells[2,7].value:='截止日期';
                excel.cells[2,8].value:='备  注';
                 //设置边框
                 excel.activesheet.range['a2:h'+InttoStr(j+2)].borders[1].weight:=2;
                 excel.activesheet.range['a2:h'+InttoStr(j+2)].borders[2].weight:=2;
                 excel.activesheet.range['a2:h'+InttoStr(j+2)].borders[3].weight:=2;
                 excel.activesheet.range['a2:h'+InttoStr(j+2)].borders[4].weight:=2;
                //对齐方式 ExlApp.Selection.HorizontalAlignment:=3;
                  excel.activesheet.columns[1].HorizontalAlignment:=3;
                  excel.activesheet.columns[2].HorizontalAlignment:=3;
                  excel.activesheet.columns[4].HorizontalAlignment:=3;
                  excel.activesheet.columns[5].HorizontalAlignment:=3;
                  excel.activesheet.columns[6].HorizontalAlignment:=3;
                  excel.activesheet.columns[7].HorizontalAlignment:=3;
                  excel.activesheet.columns[8].HorizontalAlignment:=3;
                  excel.activesheet.columns[2].verticalAlignment:=2;
                  excel.activesheet.columns[1].verticalAlignment:=2;
                  //设置自动换行
                   excel.activesheet.columns[8].WrapText:=false;
                  excel.activesheet.columns[8].ShrinkToFit:=true;
                   excel.activesheet.columns[8].ReadingOrder :=xlContext;
                   //设置页边距
                   excel.activesheet.pagesetup.topMargin:=2/0.035;
                excel.activesheet.pagesetup.headerMargin:=1.8/0.035;
                excel.activesheet.pagesetup.leftMargin:=1.5/0.035;
                excel.activesheet.pagesetup.rightMargin:=1/0.035;
                excel.activesheet.pagesetup.bottomMargin:=2/0.035;
               //设置文本属性。
               excel.activesheet.Columns['d:d'].NumberFormatLocal:='0';
               excel.activesheet.Columns['e:e'].NumberFormatLocal:='0';
               excel.activesheet.Columns['f:f'].NumberFormatLocal:='0';
               excel.activesheet.Columns['g:g'].NumberFormatLocal:='0';
               excel.activesheet.Columns['e:e'].NumberFormatLocal:='0';
               //excel.ActiveSheet.PageSetup.PrintArea :='';
               excel.ActiveSheet.PageSetup.Orientation:=xlLandscape; //横向打印        except
                exit;
            end;
           //保存为excel
            excel.displayalerts:=false;
            excel.activeworkbook.saveas('c:\gcsgl\demo.xls');
              excel.workbooks.close;
              excel.quit;
              showmessage('已保存完毕!')
    end;
      

  2.   

    // 畫框
    // XlBordersIndex 常數
    // xlDiagonalDown , xlDiagonalUp , xlEdgeBottom , xlEdgeLeft , xlEdgeRight , xlEdgeTop , xlInsideHorizontal , xlInsideVertical
    // XlLineStyle 常數
    // xlContinuous , xlDash , xlDashDot , xlDashDotDot , xlDot , xlDouble , xlSlantDashDot , xlLineStyleNone
    // XlBorderWeight 常數
    // xlHairline , xlThin , xlMedium , xlThick
    // XlColorIndex 常數
    // xlColorIndexAutomatic。 用以指定繪圖物件的自動填滿。
    // xlColorIndexNone。用以指定無內部填滿。 Range=Worksheet.OlePropertyGet("Cells",2,4);
    Range.OlePropertySet("Value","設定框線");
    Cell=Range.OlePropertyGet("Borders");
    Cell.OlePropertySet("LineStyle",xlContinuous);
    Cell.OlePropertySet("Weight",xlThin);
    Cell.OlePropertySet("ColorIndex",xlAutomatic);
    // 畫左框
    Range=Worksheet.OlePropertyGet("Cells",4,4);
    Range.OlePropertySet("Value","設定左框");
    Cell=Range.OlePropertyGet("Borders");
    Item=Cell.OlePropertyGet("Item",xlEdgeLeft);
    Item.OlePropertySet("LineStyle",xlContinuous);
    Item.OlePropertySet("Weight",xlThin);
    Item.OlePropertySet("ColorIndex",xlAutomatic);// 畫右框
    Range=Worksheet.OlePropertyGet("Cells",6,4);
    Range.OlePropertySet("Value","設定右框");
    Cell=Range.OlePropertyGet("Borders");
    Item=Cell.OlePropertyGet("Item",xlEdgeRight);
    Item.OlePropertySet("LineStyle",xlContinuous);
    Item.OlePropertySet("Weight",xlThin);
    Item.OlePropertySet("ColorIndex",xlAutomatic);// 畫上框
    Range=Worksheet.OlePropertyGet("Cells",8,4);
    Range.OlePropertySet("Value","設定上框");
    Cell=Range.OlePropertyGet("Borders");
    Item=Cell.OlePropertyGet("Item",xlEdgeTop);
    Item.OlePropertySet("LineStyle",xlContinuous);
    Item.OlePropertySet("Weight",xlThin);
    Item.OlePropertySet("ColorIndex",xlAutomatic);// 畫下框
    Range=Worksheet.OlePropertyGet("Cells",10,4);
    Range.OlePropertySet("Value","設定下框");
    Cell=Range.OlePropertyGet("Borders");
    Item=Cell.OlePropertyGet("Item",xlEdgeBottom);
    Item.OlePropertySet("LineStyle",xlContinuous);
    Item.OlePropertySet("Weight",xlThin);
    Item.OlePropertySet("ColorIndex",xlAutomatic);