<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBS: Обновление таблиц Excel по папкам]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=9187</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=9187&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBS: Обновление таблиц Excel по папкам».]]></description>
		<lastBuildDate>Mon, 03 Feb 2014 05:11:30 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: VBS: Обновление таблиц Excel по папкам]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=79728#p79728</link>
			<description><![CDATA[<p>Почитайте о операциях с файлами эксель в коллекции скриптов и идей на этом форуме. Все необходимые для решения вашей задачи примеры там есть.</p>]]></description>
			<author><![CDATA[null@example.com (Mat Skywalker)]]></author>
			<pubDate>Mon, 03 Feb 2014 05:11:30 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=79728#p79728</guid>
		</item>
		<item>
			<title><![CDATA[VBS: Обновление таблиц Excel по папкам]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=79495#p79495</link>
			<description><![CDATA[<p>Добрый день! Есть задача перенести код из Perl в VBS. Нижеизложенный скрипт обновляет файлы Эксель по указанным папкам: <br />D:\DailyReports\juristi&quot;,&quot;D:\DailyReports\ekonomisti&quot;,&quot;D:\DailyReports\sysadmini&quot;,&quot;D:\DailyReports\VIP&quot;. Если в папке содержатся файлы с расширением xlsx и xlsb, то скрипт открывает их и обновляет таблицы с данными и сводные таблицы (из внешнего источника данных).<br />Не пойму как подобное можно сделать в vbs.<br /></p><div class="codebox"><pre><code>use Env;
use Time::tm; 
use Win32;
use Win32::OLE;
use Win32::OLE::Const &#039;Microsoft Excel&#039;;
use warnings;


#===========================================================================================================================================
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$mon++;
$year = $year + 1900;
$hour--;

@dirs = (&quot;D:\\DailyReports\\juristi&quot;,&quot;D:\\DailyReports\\ekonomisti&quot;,&quot;D:\\DailyReports\\sysadmini&quot;,&quot;D:\\DailyReports\\VIP&quot;);
foreach $dir (@dirs)
{
    
    DoCommand(&quot;dir \&quot;$dir\&quot; \/A:-D \/B&quot;);
    @filez=split(/\n/,$rez);
    
    foreach $file (@filez)
    {
        $file = CodePageEncDec(&quot;$file&quot;, &quot;d2w&quot;);
        $ext=substr($file, length($file)-4, length($file));
        if (($ext eq &quot;xlsx&quot;) || ($ext eq &quot;xlsb&quot;))
        {    $filename = &quot;$dir&quot;.&quot;\\&quot;.&quot;$file&quot;;
            print(&quot;$filename\n&quot;);
            $Excel = Win32::OLE-&gt;GetActiveObject(&#039;Excel.Application&#039;) || Win32::OLE-&gt;new(&#039;Excel.Application&#039;, &#039;Quit&#039;); 
            $Excel-&gt;{Visible} = 1;
            $Excel-&gt;{DisplayAlerts} = 0;

eval {            
            $Book = $Excel-&gt;Workbooks-&gt;Open($filename);
sleep(1);
};

if ( $@ ) {
print(&quot;error open file&quot;);
}    
else {
$Book-&gt;RefreshAll;
sleep(50);
$Book-&gt;RefreshAll;
sleep(50);
my $Sheet = $Book-&gt;Worksheets(1);
$Sheet -&gt; Activate();
$Excel-&gt;{DisplayAlerts} = 1;
            $Excel-&gt;ActiveWorkbook-&gt;Save;
            $Book-&gt;Close;
            $Excel-&gt;Quit;
        };
        };
    };
};
#     S   U   B   S     =====================================================================================================================================================
# ---------------- RuN CoN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
sub DoCommand
{
  my $cmd = shift;
  $rez=&quot;&quot;;
  my $line;
  open(CMD, &quot;$cmd 2&gt;&amp;1 |&quot;);
  foreach $line (&lt;CMD&gt;)
  {
    $temp=&quot;$rez&quot;.&quot;$line&quot;;
    $rez=$temp;
  }
    close CMD;
}
# ---------------- DoS / WiN EncodinG -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
sub CodePageEncDec
{ 
  $_ = shift; 
  my ($EncDec) = @_; 
 
  my $win_chars = &quot;\xA8\xB8\xB9\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF&quot;; 
  my $dos_chars = &quot;\xF0\xF1\xFC\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF&quot;; 
 
    if ($EncDec eq &quot;d2w&quot;) {                                                      # ЏаҐаҐЄ®¤ЁагҐ¬ dos2win  
      eval(&quot;tr/$dos_chars/$win_chars/&quot;); 
    }else{                                                                       # ЏаҐаҐЄ®¤ЁагҐ¬ win2dos 
      eval(&quot;tr/$win_chars/$dos_chars/&quot;); 
    } 
  return $_; 
};</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (maratv85)]]></author>
			<pubDate>Tue, 28 Jan 2014 11:57:40 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=79495#p79495</guid>
		</item>
	</channel>
</rss>
