2023年12月13日发(作者:)
[c#]图书ISBN信息批量查询工具开发手记
0.序言
之前帮朋友做了一个利用ISBN码批量查询图书信息的小工具,这个工具难度不大,对于书店、图书馆这些很多信息需要入库的单位而言有
点作用,记录一下开发过程。先上程序截图:
1.程序原理
程序用到了,这个库网上可以下载,主要用于表格读取写入。
**1.1.选择按钮:**用于选择存储ISBN信息的表格文件
if (alog() == )
{
= me;
ISBNFilePath = me;
Workbook workbook = new Workbook(ISBNFilePath);
Cells cells = eets[0].Cells;
= "共有" + (aRow + 1) + "个ISBN码需要查询!";
d = true;
}
**1.2.分析按钮:**用于调用网络接口查询ISBN编码对应的图书信息
private void AnysisBtn_Click(object sender, EventArgs e)
{
();
d = false;
Thread GetSoundIdsWork = new Thread(new ThreadStart(getDetail));
ground = true;
();
}
private void getDetail()
{
Workbook workbook = new Workbook(ISBNFilePath);
Cells cells = eets[0].Cells;
bool isError = false;
try
try
{
for (int i = 0; i < aRow + 1; i++)
{
= "正在分析第" + (i + 1) + "/" + (aRow + 1) + "个ISBN……";
string ISBN = cells[i, 0].();
string url = @"/v2/book/isbn/" + ISBN;
string htmlStr = Client(url);
string authorTemp, author, publisherTemp, publisher, titleTemp, title, summaryTemp, summary, priceTemp, price;
if (htmlStr == "数据库未收录该ISBN!")
{
isError = true;
author = "无数据";
publisher = "无数据";
title = "无数据";
summary = "无数据";
price = "无数据";
}
else
{
try
{
authorTemp = ing(f(""author":["") + 11);
author = ing(0, f(""]")).Replace(@"n", "").Replace(@"", ",").Replace(""","").Trim();
if (author == "")
author = "无";
}
catch
{
authorTemp = htmlStr;
author = "无";
}
publisherTemp = ing(f(""publisher":"") + 13);
publisher = ing(0, f("",")).Replace(@"n", "").Trim();
if (publisher == "")
publisher = "无";
titleTemp = ing(f(""title":"") + 9);
title = ing(0, f("",")).Replace(@"n", "").Trim();
if (title == "")
title = "无";
summaryTemp = ing(f(""summary":"") + 11);
summary = ing(0, f("",")).Replace(@"n", "").Trim();
if (summary == "")
summary = "无";
priceTemp = ing(f(""price":"") + 9);
price = ing(0, f(""}")).Replace(@"n", "").Trim();
if (price == "")
price = "无";
}
int index = ();
[index].Cells[0].Value = ISBN;
[index].Cells[1].Value = title;
[index].Cells[2].Value = author;
[index].Cells[3].Value = publisher;
[index].Cells[4].Value = price;
[index].Cells[5].Value = summary;
[index].Cells[6].Value = htmlStr;
}
}
if (isError)
("查询完毕,部分图书未查询到!");
else
("查询完毕!");
d = true;
d = true;
}
catch (Exception ex)
{
(ng());
= "网络连接失败!";
d = true;
}
}
**1.3.导出按钮:**用于导出查询到的图书信息
private void ToXlsBtn_Click(object sender, EventArgs e)
{
if (alog() == )
{
string xlsPath = me;
//定义表格
Workbook UserData = new Workbook();
Worksheet sheet = eets[0];
Cells cells = ;
#region 定义表格样式
gin = 2.5;
Margin = 2.5;
rgin = 1.5;
argin = 1.5;
//大标题样式
Style style_header = [()];
style_ntalAlignment = ;//文字居中
style_alAlignment = ;
style_ = "方正小标宋简体";//文字字体
style_ = 22;//文字大小
//小标题样式
Style style_title = [()];
style_ntalAlignment = ;//文字居中
style_alAlignment = ;
style_ = "黑体";//文字字体
style_ = 11;//文字大小
style_s[Border].LineStyle = ; //应用边界线 下边界
style_s[der].LineStyle = ; //应用边界线 上边界
style_s[rder].LineStyle = ; //应用边界线 左边界
style_s[order].LineStyle = ; //应用边界线 右边界
//内容样式
Style style_common = [()];
style_ntalAlignment = ;
style_alAlignment = ;
style_ = "宋体";
style_ = 11;
style_Wrapped = true; //自动换行
style_s[Border].LineStyle = ; //应用边界线 下边界
style_s[der].LineStyle = ; //应用边界线 上边界
style_s[rder].LineStyle = ; //应用边界线 左边界
style_s[order].LineStyle = ; //应用边界线 右边界
//内容样式2
//内容样式2
Style style_common2 = [()];
style_alAlignment = ;
style_ = "宋体";
style_ = 11;
style_s[Border].LineStyle = ; //应用边界线 下边界
style_s[der].LineStyle = ; //应用边界线 上边界
style_s[rder].LineStyle = ; //应用边界线 左边界
style_s[order].LineStyle = ; //应用边界线 右边界
#endregion
#region 设置行高
Height(0, 40);
Height(1, 20);
#endregion
#region 设置各列宽
umnWidth(0, 20);//设置第1列宽
umnWidth(1, 40);//设置第2列宽
umnWidth(2, 30);//设置第3列宽
umnWidth(3, 20);//设置第4列宽
umnWidth(4, 20);//设置第5列宽
umnWidth(5, 150);//设置第6列宽
umnWidth(6, 150);//设置第7列宽
#endregion
#region 合并单元格
//标题
(0, 0, 1, 7);
#endregion
#region 设置公共内容
cells[0, 0].Value = "ISBN查询结果";
cells[0, 0].SetStyle(style_header);
cells[1, 0].Value = "ISBN";
cells[1, 0].SetStyle(style_title);
cells[1, 1].Value = "书名";
cells[1, 1].SetStyle(style_title);
cells[1, 2].Value = "作者";
cells[1, 2].SetStyle(style_title);
cells[1, 3].Value = "出版社";
cells[1, 3].SetStyle(style_title);
cells[1, 4].Value = "价格";
cells[1, 4].SetStyle(style_title);
cells[1, 5].Value = "简介";
cells[1, 5].SetStyle(style_title);
cells[1, 6].Value = "源代码";
cells[1, 6].SetStyle(style_title);
#endregion
#region 写入内容
for (int i = 0; i < ; i++)
{
//行高
Height(i + 2, 100);
//ISBN
cells[i + 2, 0].Value = [i].Cells[0].ng();
cells[i + 2, 0].SetStyle(style_common);
//书名
cells[i + 2, 1].Value = [i].Cells[1].ng();
cells[i + 2, 1].SetStyle(style_common);
//作者
cells[i + 2, 2].Value = [i].Cells[2].ng();
cells[i + 2, 2].SetStyle(style_common);
//出版社
cells[i + 2, 3].Value = [i].Cells[3].ng(); cells[i + 2, 3].Value = [i].Cells[3].ng(); cells[i + 2, 3].SetStyle(style_common); //价格 cells[i + 2, 4].Value = [i].Cells[4].ng(); cells[i + 2, 4].SetStyle(style_common); //简介 cells[i + 2, 5].Value = [i].Cells[5].ng(); cells[i + 2, 5].SetStyle(style_common); //源代码 cells[i + 2, 6].Value = [i].Cells[6].ng(); cells[i + 2, 6].SetStyle(style_common); } #endregion (xlsPath); ("导出成功!"); }}2.下载地址


发布评论