仅打印工作簿中的所有电子表格名称

发布于 2024-07-26 07:31:57 字数 268 浏览 2 评论 0原文

是否可以仅打印电子表格名称(选项卡底部的名称)? 我有一本工作簿,里面有很多电子表格(超过 500 个,呃,这是一个音乐目录……CD,里面有什么,作曲家,指挥家,乐章,时间等),我想打印出来工作簿的名称,而不是全部和每个部分的名称。 是的,我知道我很可能应该在 Access 中执行此操作,但 64 年前我在 Commidore 上开始使用它,并且一直在“转换”它。 最新版本是 Excel 2007。因此本质上它是使用电子表格完成的“2D 数据库”,而不是在 Access 中完成的“3D 数据库”。 许多问候。

Is it possible to print ONLY the spreadsheets names (the names at the bottom on the tabs)?
I have a workbook with quite a lot of spreasheets (over 500, er, it's a catalogue of music... CDs, what's on them, composors, conductors, movements, times etc.) and would like to do a print out of just the names of, not all and every part of the workbook.
Yes I know I should more than likely do this in Access, but I started it on a Commidore 64 years ago and have just been 'converting' it as I go along. Latest version is in Excel 2007. So esentially it's a '2D database' done using spreadsheets, rather than a '3D database' done in Access.
Many regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

南街九尾狐 2024-08-02 07:31:58

使用 VBA,您可以非常轻松地将工作表名称列表转储到工作簿中的新工作表中。

Sub PrintSheetNames()
   i=1
   For Each sht in Sheets
      Cells(i,1).Value = sht.Name
      i=i+1
   Next
End Sub

转到任何空白工作表,然后运行此宏。 它将输出第一列中的所有工作表名称。 然后您只需打印该列表即可。

Using VBA you can pretty easily dump the list of sheet names to a new sheet in your workbook.

Sub PrintSheetNames()
   i=1
   For Each sht in Sheets
      Cells(i,1).Value = sht.Name
      i=i+1
   Next
End Sub

Go to any blank worksheet, and then run this macro. It will output all the worksheet names in the first column. You can then just print the list.

瑶笙 2024-08-02 07:31:58

假设您使用 VBA 而不是 .NET,您可以编写与此类似的子例程。 .NET 中提供了相同的对象和名称。

Sub ShowTabNames()
    Dim s As Worksheet
    Dim tabs As String

    For Each s In ActiveWorkbook.Worksheets
        If Len(tabs) > 0 Then tabs = tabs & ", "
        tabs = tabs & s.Name
    Next

    MsgBox tabs
End Sub

Assuming you using VBA and not .NET you could write a sub routine similar to this. The same objects and names are available in .NET.

Sub ShowTabNames()
    Dim s As Worksheet
    Dim tabs As String

    For Each s In ActiveWorkbook.Worksheets
        If Len(tabs) > 0 Then tabs = tabs & ", "
        tabs = tabs & s.Name
    Next

    MsgBox tabs
End Sub
你怎么这么可爱啊 2024-08-02 07:31:58

您可以使用 Perl 和 Spreadsheet::ParseExcel 模块已安装。

use Spreadsheet::ParseExcel;
use strict;

my $filename = shift || "Book1.xls";
my $e = new Spreadsheet::ParseExcel;
my $eBook = $e->Parse($filename);
my $sheets = $eBook->{SheetCount};
my ($eSheet, $sheetName);

foreach my $sheet (0 .. $sheets - 1) {
    $eSheet = $eBook->{Worksheet}[$sheet];
    $sheetName = $eSheet->{Name};
    print "Worksheet $sheet: $sheetName\n";
}

You can do this using Perl with Spreadsheet::ParseExcel module installed.

use Spreadsheet::ParseExcel;
use strict;

my $filename = shift || "Book1.xls";
my $e = new Spreadsheet::ParseExcel;
my $eBook = $e->Parse($filename);
my $sheets = $eBook->{SheetCount};
my ($eSheet, $sheetName);

foreach my $sheet (0 .. $sheets - 1) {
    $eSheet = $eBook->{Worksheet}[$sheet];
    $sheetName = $eSheet->{Name};
    print "Worksheet $sheet: $sheetName\n";
}
指尖微凉心微凉 2024-08-02 07:31:58

您可以创建一个 OleDbConnection 到 Excel 工作簿,然后调用 GetOleDbSchemaTable 来获取所有表的列表,这些表只不过是 Excel 工作表列表

ExcelConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null , “桌子” });

You can make a OleDbConnection to your Excel workbook then call GetOleDbSchemaTable to get list of all tables which are nothing but list of excel sheets

ExcelConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });

破晓 2024-08-02 07:31:58

您可以使用安装了 xlrd 模块的 Python 来执行此操作

import xlrd, sys
filename = (sys.argv[1:2] or ['Book1.xls'])[0]
book = xlrd.open_workbook(filename, on_demand=True)
for name in book.sheet_names():
    print name # name is in Unicode; may need encoding

on_demand arg 是 0.7.1 版本中的新增内容; 它无需预先解析所有工作表,从而节省时间和内存。 如果您有早期版本,请升级或删除上面代码段中的 on_demand=True

You can do this using Python with the xlrd module installed:

import xlrd, sys
filename = (sys.argv[1:2] or ['Book1.xls'])[0]
book = xlrd.open_workbook(filename, on_demand=True)
for name in book.sheet_names():
    print name # name is in Unicode; may need encoding

Note: the on_demand arg is new in version 0.7.1; it allows saving time and memory by not parsing all the worksheets up front. If you have an earlier version, either upgrade or remove on_demand=True in the snippet above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文