0.序言
之前帮朋友做了一个利用ISBN码批量查询图书信息的小工具,这个工具难度不大,对于书店、图书馆这些很多信息需要入库的单位而言有点作用,记录一下开发过程。先上程序截图:
1.程序原理
程序用到了Aspose.Cells.dll,这个库网上可以下载,主要用于表格读取写入。
**1.1.选择按钮:**用于选择存储ISBN信息的表格文件
if (openISBNFileDialog.ShowDialog() == DialogResult.OK)
{
ISBNFilePathBox.Text = openISBNFileDialog.FileName;
ISBNFilePath = openISBNFileDialog.FileName;
Workbook workbook = new Workbook(ISBNFilePath);
Cells cells = workbook.Worksheets[0].Cells;
workState.Text = "共有" + (cells.MaxDataRow + 1) + "个ISBN码需要查询!";
AnysisBtn.Enabled = true;
}
**1.2.分析按钮:**用于调用网络接口查询ISBN编码对应的图书信息
private void AnysisBtn_Click(object sender, EventArgs e)
{
DownloadList.Rows.Clear();
AnysisBtn.Enabled = false;
Thread GetSoundIdsWork = new Thread(new ThreadStart(getDetail));
GetSoundIdsWork.IsBackground = true;
GetSoundIdsWork.Start();
}
private void getDetail()
{
Workbook workbook = new Workbook(ISBNFilePath);
Cells cells = workbook.Worksheets[0].Cells;
bool isError = false;
try
{
for (int i = 0; i < cells.MaxDataRow + 1; i++)
{
workState.Text = "正在分析第" + (i + 1) + "/" + (cells.MaxDataRow + 1) + "个ISBN……";
string ISBN = cells[i, 0].StringValue.Trim();
string url = @"https://api.douban.com/v2/book/isbn/" + ISBN;
string htmlStr = CommonMethds.GetWebClient(url);
string authorTemp, author, publisherTemp, publisher, titleTemp, title, summaryTemp, summary, priceTemp, price;
if (htmlStr == "数据库未收录该ISBN!")
{
isError = true;
author = "无数据";
publisher = "无数据";
title = "无数据";
sum