留着以后能有用
- using System.Reflection;
- using MSExcel = Microsoft.Office.Interop.Excel;
- using Microsoft.Office.Interop.Excel;
- namespace ConsoleApplication2
- {
- class shelf
- {
- private static int sum = 0;
- private static MSExcel.Application appExcel;
- private static MSExcel.Workbook excelDoc;
- private static object format = MSExcel.XlFileFormat.xlWorkbookNormal;
- private static Object Nothing = Missing.Value;
- static void Main(string[] args)
- {
- int line;
- Console.Write("输入排数:");
- line = Convert.ToInt32(Console.ReadLine());
- int ShelfNumber, LayerNumber;
- Console.Write("输入货架数:");
- ShelfNumber = Convert.ToInt32(Console.ReadLine());
- Console.Write("输入层数:");
- LayerNumber = Convert.ToInt32(Console.ReadLine());
- int[] Number = new int[ShelfNumber];
- for (int i = 0; i < ShelfNumber; i++)
- {
- Console.WriteLine("第{0}个货架列数:", i + 1);
- Number[i] = Convert.ToInt32(Console.ReadLine());
- }
- int n;
- for (int i = LayerNumber; i > 0; i--)
- {
- for (int j = 0; j < ShelfNumber; j++)
- {
- for (int k = 0; k < Number[j]; k++)
- {
- sum++;
- }
- }
- }
- string[] strings = new string[sum];
- int index=0;
- for (int i = LayerNumber; i > 0; i--)
- {
- n = 1;
- for (int j = 0; j < ShelfNumber; j++)
- {
- for (int k = 0; k < Number[j]; k++)
- {
- strings[index++] = line.ToString().PadLeft(2, '0') + "-" + i + "-" + n.ToString().PadLeft(2, '0');
- n++;
- }
- }
- }
- shelf shelfs = new shelf();
- appExcel = new MSExcel.Application();
- excelDoc = appExcel.Workbooks.Add("D://ss.xls");
- MSExcel.Worksheet ws = (MSExcel.Worksheet)excelDoc.Sheets[1];
- string s;
- int a = 97;
- int l = 0;
- while (sum > 0)
- {
- for (int i = 1; i <= 5 && sum > 0; i++)
- {
- char c = Convert.ToChar(a);
- s = Convert.ToString(c) + i;
- Console.WriteLine(s);
- MSExcel.Range r = ws.get_Range(s, s);
- //向单元格赋值
- string sss=strings[l++];
- //r.Value2 = "="+"/""+sss+"/"";
- r.Value2 = sss ;
- //r.Columns.AutoFit();
- //r.Rows.AutoFit();
- //r.Font.Name = "Arial Unicode MS";
- //r.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- //r.VerticalAlignment = XlVAlign.xlVAlignCenter;
- //r.Font.Size = 75;
- //r.ColumnWidth = 46.75;
- //r.RowHeight = 156.75;
- //r.NumberFormatLocal = "@";
- //r.Merge(true);
- sum--;
- }
- a++;
- }
- excelDoc.SaveAs("D://ss.xls", Nothing, Nothing, Nothing, Nothing, Nothing,
- MSExcel.XlSaveAsAccessMode.xlExclusive, Nothing, Nothing, Nothing, Nothing, Nothing);
- excelDoc.Close(Nothing, Nothing, Nothing);
- appExcel.Quit();
- }
- }
- }