Что нового

Все границы в excel

ildar

Осваивающий
Сообщения
252
Репутация
29
Как нарисовать границы я нашел тут http://autoit-script.ru/index.php?topic=2224.msg16238#msg16238
Код:
$oExcel = ObjCreate('Excel.Application')
With $oExcel
    .Visible = True
    .Workbooks.Add
    .ActiveSheet.Range(.Cells(2, 2), .Cells(5, 5)).BorderAround(-4119, 4, 30)
;~  .ActiveSheet.Range(.Cells(2, 2), .Cells(5, 5)).BorderAround(-4119, 4) ; так будет черная граница
    .ActiveWorkBook.Saved = True
EndWith
обводит границу от ячейки 2,2 до ячейки 5,5 включительно.
Как нарисовать все границы, то есть обвести каждую ячейку в определенной области. Через For...To.. используя выше пример процесс довольно долгий.
 
A

Alofa

Гость
ildar сказал(а):
... Как нарисовать все границы...

Range.BorderAround Method (Excel)
This method outlines the entire range without filling it in. To set the borders of all the cells, you must set the Color , LineStyle , and Weight properties for the Borders collection. To clear the border, you must set the LineStyle property to xlLineStyleNone for all the cells in the range.
Код:
$oExcel = ObjCreate('Excel.Application')
With $oExcel
    .Visible = True
    .Workbooks.Add
    .ActiveSheet.Range(.Cells(2, 2), .Cells(5, 5)).Borders.LineStyle = -4119
    .ActiveWorkBook.Saved = True
EndWith
 
Автор
ildar

ildar

Осваивающий
Сообщения
252
Репутация
29
Alofa
Спасибо! Borders.LineStyle это мне и надо было.
 

pvnn

Осваивающий
Сообщения
305
Репутация
32
Если нужно быстро нарисовать границы (без цикла With $oExcel)
Код:
#include <Excel.au3>

$oExcel = ObjCreate('Excel.Application') ; Создать объект
$oExcel.Visible = True
$oExcel.Workbooks.Add


; Переменные Excel
 $xlThin=2
 $xlDiagonalDown=5
 $xlDiagonalUp=6
 $xlEdgeLeft=7
 $xlEdgeTop=8
 $xlEdgeBottom=9
 $xlEdgeRight=10
 $xlInsideVertical=11
 $xlInsideHorizontal=12

; Быстрое Рисование указанных границ
Local $loRange=$oExcel.ActiveSheet.Range($oExcel.Cells(1, 1).Address&':'&$oExcel.Cells(10, 5).Address)
;Local $loRange=$oExcel.ActiveSheet.Range('A1:E10') ; Можно указать и диапазон
	$loRange.Borders($xlEdgeLeft).Weight = $xlThin
	$loRange.Borders($xlEdgeTop).Weight = $xlThin
	$loRange.Borders($xlEdgeBottom).Weight = $xlThin
	$loRange.Borders($xlEdgeRight).Weight = $xlThin
    $loRange.Borders($xlInsideVertical).Weight =$xlThin
	$loRange.Borders($xlInsideHorizontal).Weight = $xlThin
 
A

Alofa

Гость
pvnn сказал(а):
... (без цикла With $oExcel)...
With...EndWith - это не цикл.

pvnn сказал(а):
Если нужно быстро нарисовать границы...
А разве так не проще?
Код:
With ObjCreate('Excel.Application')
	.Visible = True
	.Workbooks.Add
	.ActiveSheet.Range('A1:E10').Borders.Weight = 2
EndWith
 
Верх