From 164b0beebc55a1ff60827127c5781fcae877ca26 Mon Sep 17 00:00:00 2001 From: Dazai Xu Date: Tue, 12 May 2020 12:28:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E7=BB=88=E6=88=90=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.config | 6 + "Framework\345\217\221\347\245\250.csproj" | 109 ++++++++++++++ "Framework\345\217\221\347\245\250.sln" | 25 ++++ Program.cs | 158 +++++++++++++++++++++ Properties/AssemblyInfo.cs | 36 +++++ 5 files changed, 334 insertions(+) create mode 100644 App.config create mode 100644 "Framework\345\217\221\347\245\250.csproj" create mode 100644 "Framework\345\217\221\347\245\250.sln" create mode 100644 Program.cs create mode 100644 Properties/AssemblyInfo.cs diff --git a/App.config b/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/Framework\345\217\221\347\245\250.csproj" "b/Framework\345\217\221\347\245\250.csproj" new file mode 100644 index 0000000..0492834 --- /dev/null +++ "b/Framework\345\217\221\347\245\250.csproj" @@ -0,0 +1,109 @@ + + + + + Debug + AnyCPU + {86363AAC-22D9-4523-8DC0-A3BECBE90C06} + Exe + Framework发票 + Framework发票 + v4.7.2 + 512 + true + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52} + 2 + 8 + 0 + primary + False + True + + + {00020813-0000-0000-C000-000000000046} + 1 + 9 + 0 + primary + False + True + + + {0002E157-0000-0000-C000-000000000046} + 5 + 3 + 0 + primary + False + True + + + + + False + Microsoft .NET Framework 4.7.2 %28x86 和 x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git "a/Framework\345\217\221\347\245\250.sln" "b/Framework\345\217\221\347\245\250.sln" new file mode 100644 index 0000000..9ec453b --- /dev/null +++ "b/Framework\345\217\221\347\245\250.sln" @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29911.84 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework发票", "Framework发票.csproj", "{86363AAC-22D9-4523-8DC0-A3BECBE90C06}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {86363AAC-22D9-4523-8DC0-A3BECBE90C06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86363AAC-22D9-4523-8DC0-A3BECBE90C06}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86363AAC-22D9-4523-8DC0-A3BECBE90C06}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86363AAC-22D9-4523-8DC0-A3BECBE90C06}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D0D58A98-7A0D-4B30-BB10-87CADD986AD9} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..8319381 --- /dev/null +++ b/Program.cs @@ -0,0 +1,158 @@ +using System; +using Excel = Microsoft.Office.Interop.Excel; +using System.IO; +using System.Text; + + +namespace FrameWork发票 +{ + class Program + { + static void Main(string[] args) + { + ExcelOp eo = new ExcelOp(); + //Console.WriteLine("请输入税控盘持有人姓名:"); + + + Console.WriteLine("请讲文件拖入此处(文件的名称格式为:xx商品编码,xx为税控盘名称!且软件运行后生成的excel文件在 《文档》 文件夹中)\n"); + string fullname = Console.ReadLine(); + + Console.WriteLine("\n正在转换中,请耐心等待。。。"); + string name = fullname.Substring(fullname.IndexOf(".") - 6,6); + eo.CreateExcelFile(name); + object Nothing = System.Reflection.Missing.Value; + Excel.Application app = new Excel.Application(); + app.Visible = false; + + //string item = eo.Read(string.Format("E://个人文件//妈妈//{0}商品编码.txt",name)); + string item = eo.Read(fullname); + int i = item.IndexOf(""); + int i_ = item.IndexOf(""); + try + { + while (i != -1) + { + Excel.Workbook mybook = app.Workbooks.Open(name, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing); + Excel.Worksheet mysheet = (Excel.Worksheet)mybook.Worksheets[1]; + int i1 = item.IndexOf(""); + int i1_ = item.IndexOf(""); + int i2 = item.IndexOf(""); + int i2_ = item.IndexOf(""); + int i3 = item.IndexOf(""); + int i3_ = item.IndexOf(""); + int i4 = item.IndexOf(""); + int i4_ = item.IndexOf(""); + int i5 = item.IndexOf(""); + int i5_ = item.IndexOf(""); + int i6 = item.IndexOf(""); + int i6_ = item.IndexOf(""); + int i7 = item.IndexOf(""); + int i7_ = item.IndexOf(""); + int i8 = item.IndexOf(""); + int i8_ = item.IndexOf(""); + int i9 = item.IndexOf(""); + int i9_ = item.IndexOf(""); + int i10 = item.IndexOf("");//优惠政策类型 + int i10_ = item.IndexOf(""); + int i11 = item.IndexOf("");//免税类型 + int i11_ = item.IndexOf(""); + + string c1 = item.Substring(i1 + 6, i1_ - i1 - 6); + string c2 = item.Substring(i2 + 6, i2_ - i2 - 6); + string c3 = item.Substring(i3 + 4, i3_ - i3 - 4); + string c4 = item.Substring(i4 + 8, i4_ - i4 - 8); + string c5 = item.Substring(i5 + 7, i5_ - i5 - 7); + string c6 = item.Substring(i6 + 6, i6_ - i6 - 6); + string c7 = item.Substring(i7 + 6, i7_ - i7 - 6); + string c8 = item.Substring(i8 + 6, i8_ - i8 - 6); + string c9 = item.Substring(i9 + 6, i9_ - i9 - 6); + string c10 = item.Substring(i10 + 4, i10_ - i10 - 4); + string c11 = item.Substring(i11 + 6, i11_ - i11 - 6); + eo.WriteToExcel("全部商品", c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, mybook, mysheet, Nothing, app); + item = item.Remove(0, i_ + 7); + i = item.IndexOf(""); + i_ = item.IndexOf(""); + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + finally + { + Console.WriteLine("\n转换完成!请在‘我的文档’中查找点击!输入回车自动退出。"); + Console.ReadKey(); + app.Quit(); + } + + + + } + + } + class ExcelOp + { + public string Read(string path) + { + StreamReader sr = new StreamReader(path, Encoding.UTF8); + return sr.ReadToEnd(); + } + + internal void CreateExcelFile(string FileName) + { + //create + object Nothing = System.Reflection.Missing.Value; + var app = new Excel.Application(); + app.Visible = false; + Excel.Workbook workBook = app.Workbooks.Add(Nothing); + Excel.Worksheet worksheet = (Excel.Worksheet)workBook.Sheets[1]; + + worksheet.Name = FileName; + //headline + worksheet.Cells[1, 1] = "名称"; + worksheet.Cells[1, 2] = "编码"; + //worksheet.Cells[1, 2].numberFormatting = "@"; + worksheet.Cells[1, 3] = "简码"; + worksheet.Cells[1, 4] = "税收分类简称"; + worksheet.Cells[1, 5] = "税率"; + //worksheet.Cells[1, 5].numberFormatting = "formatnumber"; + worksheet.Cells[1, 6] = "规格/厂牌"; + worksheet.Cells[1, 7] = "计量单位"; + worksheet.Cells[1, 8] = "适用税率"; + worksheet.Cells[1, 9] = "含税标志"; + worksheet.Cells[1, 10] = "优惠政策类型"; + worksheet.Cells[1, 11] = "免税类型"; + + worksheet.Columns[2].NumberFormatLocal = "@";//设置第二列为 文本格式 + + worksheet.SaveAs(FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing); + workBook.Close(false, Type.Missing, Type.Missing); + + + app.Quit(); + + } + internal void WriteToExcel(string excelName, string c1, string c2, string c3, string c4, string c5, string c6, string c7, string c8, string c9, string c10, string c11, Excel.Workbook mybook, Excel.Worksheet mysheet, object Nothing, Excel.Application app) + { + //open + mysheet.Activate(); + //get activate sheet max row count + int maxrow = mysheet.UsedRange.Rows.Count + 1; + mysheet.Cells[maxrow, 1] = c1; + mysheet.Cells[maxrow, 2] = c2; + mysheet.Cells[maxrow, 3] = c3; + mysheet.Cells[maxrow, 4] = c4; + mysheet.Cells[maxrow, 5] = c5; + mysheet.Cells[maxrow, 6] = c6; + mysheet.Cells[maxrow, 7] = c7; + mysheet.Cells[maxrow, 8] = c8; + mysheet.Cells[maxrow, 9] = c9; + mysheet.Cells[maxrow, 10] = c10; + mysheet.Cells[maxrow, 11] = c11; + mybook.Save(); + mybook.Close(false, Type.Missing, Type.Missing); + mybook = null; + } + } +} + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2f026b2 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Framework发票")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Framework发票")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("86363aac-22d9-4523-8dc0-a3becbe90c06")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]