为了保留源工作表的原始格式,请使用以下内容:
For r = LBound(x, 1) To UBound(x, 1)
For c = LBound(x, 2) To UBound(x, 2)
NewWS.Rows(r).RowHeight = WS.Cells(r, c).RowHeight
NewWS.Columns(c).ColumnWidth = WS.Cells(r, c).ColumnWidth
With NewWS.Cells(r, c)
.Font.Bold = WS.Cells(r, c).Font.Bold
.Borders(xlEdgeBottom).LineStyle = WS.Cells(r, c).Borders(xlEdgeBottom).LineStyle
.Borders(xlEdgeLeft).LineStyle = WS.Cells(r, c).Borders(xlEdgeLeft).LineStyle
.Borders(xlEdgeRight).LineStyle = WS.Cells(r, c).Borders(xlEdgeRight).LineStyle
.Interior.ColorIndex = WS.Cells(r, c).Interior.ColorIndex
.Orientation = WS.Cells(r, c).Orientation
.Font.Size = WS.Cells(r, c).Font.Size
.HorizontalAlignment = WS.Cells(r, c).HorizontalAlignment
.VerticalAlignment = WS.Cells(r, c).VerticalAlignment
.MergeCells = WS.Cells(r, c).MergeCells
.Font.FontStyle = WS.Cells(r, c).Font.FontStyle
.Font.Name = WS.Cells(r, c).Font.Name
.ShrinkToFit = WS.Cells(r, c).ShrinkToFit
.NumberFormat = WS.Cells(r, c).NumberFormat
End With
Next
Next
这将解决大多数格式问题;根据需要添加其他单元格属性。