一:Word文档
针对命题,如果是Word文档,那很好实现:
比如:你在文档中插入两行两列的表格,想将其打印到纸张上,打印出来的每个单元格高、宽分别都是6厘米,以方便照片精确地粘贴到上面……
在WORD里面,有多种单位,常用的就是磅和厘米等;
由于提供了CM为度量单位,要实现效果就好办得多了!
首先把整个表格全部选中,在表格上点右键,执行“表格属性”操作,弹出如下图的对话框;
上图中,我们可以设置行、列的高、宽,以此达到目的先;
注意,有的网友使用的WORD软件,里面提供的默认的单位是磅,而不是厘米;这个时候勿急,请根据上图,直接输入值与单位即可,如本例的6 厘米;注意:6和厘米之间是一个英文状态下的空格,勿要错了!这样就可以覆盖原来的磅单位,并以CM为单位了,如果默认的单位是厘米,直接输入一个值即可;设置好了之后,按“确定”确认并退出即可;
如此一来,将表格打印出来,就是每个单元格的高和宽分别都为6厘米的大小了,咋样,很方便吧!
本人在办公室使用直尺量过(不过也浪费了一纸张),完全正确,阁下但做无妨!
二:Excel文档
针对这种文档,麻烦非常大,原因只有一个,那就是不支持厘米作为度量单位;
这个时候,我们要实现命题的效果,只能使用两招:
①招:
根据单位换算的关系,设定厘米对应的磅值大小;一厘米大概等于28.57143磅,即1CM=28.57143磅;(6厘米等于多少磅呢?)大家可能已发现了,这种换算关系只是一种近似值,所以,难于精确到位,只能做个差强人意的近似换算;但是,蛮天不过,蛮地不成,蛮人的眼睛(视觉惰性)应该没有问题滴!只要值取得越近似,人的眼睛就越觉察不到!
②招:得使用不为常人使用的VBA绝招了
以下提供源代码,能利用则利用,不能利用就按上述方法实现吧,该问题非己之过,俺也没理亏!!
===代码开始===
Sub MakeRuler_cm()'以厘米為單位
'Define the size of a new ruler.
Const Ruler_Width As Double = 10 'Width 16 cm
Const Ruler_Height As Double = 10 'Height 14 cm
'The setting size on the screen and the actual size on the printer.
Const Screen_Width As Double = 16
Const Screen_Height As Double = 14
Const Printer_Width As Double = 16
Const Printer_Height As Double = 14
Dim i As Long
Dim l As Long
Dim x As Long
Dim y As Long
Dim ws As Worksheet
Dim x2 As Double
Dim y2 As Double
x = Ruler_Width * 10
y = Ruler_Height * 10
Application.ScreenUpdating = False
Set ws = ActiveSheet
Worksheets.Add
ActiveSheet.Move
ActiveSheet.Lines.Add 0, 0, 3 * x, 0
For i = 1 To x
If i Mod 10 = 0 Then l = 5 Else: If i Mod 5 = 0 Then l = 4 Else l = 3
ActiveSheet.Lines.Add 3 * i, 0, 3 * i, 3 * l
Next
ActiveSheet.Lines.Add 0, 0, 0, 3 * y
For i = 1 To y
If i Mod 10 = 0 Then l = 5 Else: If i Mod 5 = 0 Then l = 4 Else l = 3
ActiveSheet.Lines.Add 0, 3 * i, 3 * l, 3 * i
Next
ActiveSheet.Lines.Border.ColorIndex = 55
For i = 10 To x - 1 Step 10
With ActiveSheet.TextBoxes.Add(3 * i - 9, 3 * 5, 18, 12)
.Text = Format(i \ 10, "!@@")
End With
Next
For i = 10 To y - 1 Step 10
With ActiveSheet.TextBoxes.Add(3 * 5, 3 * i - 9, 12, 18)
.Orientation = xlDownward
.Text = Format(i \ 10, "!@@")
End With
Next
With ActiveSheet.TextBoxes
.Font.Size = 9
.Font.ColorIndex = 55
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Border.ColorIndex = xlNone
.Interior.ColorIndex = xlNone
End With
With ActiveSheet.DrawingObjects.Group
.Placement = xlFreeFloating
.Width = Application.CentimetersToPoints(x / 10)
.Height = Application.CentimetersToPoints(y / 10)
.CopyPicture xlScreen, xlPicture
ActiveSheet.Paste
x2 = (Selection.Width - .Width) / 3
y2 = (Selection.Height - .Height) / 3
Selection.Delete
.CopyPicture xlPrinter, xlPicture
ActiveSheet.Paste
.Width = .Width * .Width / (Selection.Width - x2 * 2) * Screen_Width / Printer_Width
.Height = .Height * .Height / (Selection.Height - y2 * 2) * Screen_Height / Printer_Height
Selection.Delete
If Val(Application.Version) >= 9 Then
.Copy
ActiveSheet.PasteSpecial 'Format:="Picture (PNG)"
With Selection.ShapeRange.PictureFormat
.CropLeft = x2
.CropTop = y2
.CropRight = x2
.CropBottom = y2
End With
Selection.Copy
ws.Activate
ws.PasteSpecial 'Format:="Picture (PNG)"
Selection.Placement = xlFreeFloating
.Parent.Parent.Close False
End If
End With
Application.ScreenUpdating = True
End Sub
==代码结束===
代码为网上提供的,版权归原作者所有,本文仅为方便大家学习,特搬到这里来!