Импортирую простые таблицы из интернета при помощи кода:
Скрытый текст |
---|
Код |
---|
Sub PasteTable()
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://example.com" & ActiveCell.Value _
, Destination:=Cells(ActiveCell.Row + 1, 1))
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "1" ' this is the number of the required table on a page
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = True
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub |
|
На страницах все таблицы однотипные и имеют вид:
Скрытый текст |
---|
Код |
---|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Catalog</title>
<style type="text/css">
body { background:#09314a; background: linear-gradient(to bottom, #09314a, #49b3c1); font-family:Arial; font-size:small; padding:20px 0px;}
.content2 {width: 85%; min-width:900px; margin:0 auto; padding: 5px 14px 20px 14px; background-color: #f7f7f9; border: 1px solid #e1e1e8; border-radius:4px;}
.headtitle { width:100%; margin:0px; padding:0px; }
.left_headtitle {width:35%; float: left; padding:20px 0px 0px 0px; margin:0px; vertical-align:middle; }
.right_headtitle {width: 65%; height: 155px; position: relative; z-index:3; padding:0px; display:block; text-align:right; overflow-x: auto; overflow-y: hidden; white-space: nowrap;}
h1 {width: 85%; min-width:900px; margin:0 auto; color:white; font-size:x-large; font-weight:normal; font-family:Verdana, Geneva, Tahoma, sans-serif; padding:0px 0px 16px 0px; }
h2 {color:#208FFF; font-size: medium; padding:10px 0px 0px 0px; margin-top:0px}
.tabs { width:100%; position: relative; margin: 0px 0px 25px 0px; top:-22px; }
.tab label {position: relative; left: 1px; top:0px; background: white; margin-left:-1; padding: 10px 20px; font-weight:bold; border-left: 1px solid #ccc; border-right: 1px solid #ccc; border-top: 1px solid #ccc; border-bottom: 1px solid white; border-radius:6px 6px 0px 0px; z-index:2;}
.content {width:100%; position:relative; z-index:1; background: white; right: 0; top:8px; padding: 20px 0px;
border: 1px solid #ccc; border-radius:0px 4px 4px 4px;}
table { margin:0px 5px;width:98%; }
th {text-align:left; border-bottom: 2px solid gray; padding:8px; font-size:small; }
tr { border-color: inherit; box-sizing: border-box;}
td{padding:4px 8px;color: #333; border-bottom: 1px solid #ddd; border-color:#C1C1C1; font-size:small; vertical-align:top; }
.general {background-color: #d9edf7; border-bottom: 2px solid gray; border-top: 2px solid gray;}
.headimg { height:125px; background-color: #fff; display: inline-block; vertical-align: middle; padding:4px 0px 4px 4px; margin-left: 5px; transition: all .2s ease-in-out; line-height: 1.42857143; border: 1px solid #ddd; border-radius: 4px; }
.valuestyle {color:#808080;}
.tvhead1 {width:80px;}
.tvhead2 {min-width:150px !important;}
</style>
</head>
<body>
<h1>ContentStream </h1>
<div class="content2">
<div class="headtitle">
<div class="left_headtitle">
<h2>Product id:
xxxxxxxxxxxxxxx</h2>
</div>
<div class="right_headtitle"></div>
</div>
<div class="tabs">
<div class="tab">
<label>Карточка</label>
<div class="content">
<table cellpadding="0" cellspacing="0">
<tbody><tr>
<th>Group</th><th>Attribute</th><th>Value</th>
</tr>
<tr class="general">
<td colspan="3">
<p>Group1</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute1<br>
</td><td>
<p>Value1<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute2<br>
</td><td>
<p>Value2<br>
</p>
</td>
</tr>
<tr class="general">
<td colspan="3">
<p>Group2</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute3<br>
</td><td>
<p>Value3<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute4<br>
</td><td>
<p>Value4<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute5<br>
</td><td>
<p>Value5<br>
</p>
</td>
</tr>
<tr class="general">
<td colspan="3">
<p>Group3</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute6<br>
</td><td>
<p>Value6<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute7<br>
</td><td>
<p>Value7<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute8<br>
</td><td>
<p>Value8<br>
</p>
</td>
</tr>
<tr class="general">
<td colspan="3">
<p>Group3</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute9<br>
</td><td>
<p>Value9<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute10<br>
</td><td>
<p>Value10<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute11<br>
</td><td>
<p>Value11<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute12<br>
</td><td>
<p>Value12<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute13<br>
</td><td>
<p>Value13<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute14<br>
</td><td>
<p>Value14<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute15<br>
</td><td>
<p>Value15<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute16<br>
</td><td>
<p>Value16<br>
</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute17<br>
</td><td>
<p>Value17<br>
</p>
</td>
</tr>
<tr class="general">
<td colspan="3">
<p>Group</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute18<br>
</td><td>
<p>Value18<br>
</p>
</td>
</tr>
<tr class="general">
<td colspan="3">
<p>Group</p>
</td>
</tr>
<tr>
<td class="tvhead1">
<p></p>
</td><td class="tvhead2">Attribute19<br>
</td><td>
<p>Value19<br>
</p>
</td>
</tr>
</tbody></table>
</div>
</div>
</div>
</div>
</body></html> |
|
При импорте таблиц, в документе после окончания операции они принимают такой вид:
А нужно, чтобы после импорта таблицы принимали такой вид:
После импорта таблицы в рабочую книгу я вручную перемещаю все ячейки первого столбца таблицы на одну ячейку вниз, после этого я удаляю все строки, в которых ячейки C пустые, а так же удаляю первую строку таблицы.
Подскажите, пожалуйста, как сделать так, чтобы при импорте таблиц из интернета, они автоматически принимали нужный мне формат.