private void OutPutExcel_N4Nguphap(DataTable adtData) { string templatePath = Common.GetTemplate("N4Nguphap_テンプレート.xls"); SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(templatePath); try { SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets["N4Nguphap"]; SpreadsheetGear.IRange range = null; //tb.Columns.Add("id"); //tb.Columns.Add("maucau"); //tb.Columns.Add("cachchia"); //tb.Columns.Add("ynghia"); //tb.Columns.Add("vidu"); string dataA, dataB, dataC, dataD, dataE; string[] numofLineA, numofLineB, numofLineC, numofLineD, numofLineE; for (int i = 0, addressY = 2, plus = 0; i < adtData.Rows.Count; i++, addressY++, plus = 0) { dataA = adtData.Rows[i]["id"].ToString(); dataB = adtData.Rows[i]["maucau"].ToString(); dataC = adtData.Rows[i]["cachchia"].ToString(); dataD = adtData.Rows[i]["ynghia"].ToString(); dataE = adtData.Rows[i]["vidu"].ToString(); numofLineA = dataA.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); numofLineB = dataB.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); numofLineC = dataC.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); numofLineD = dataD.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); numofLineE = dataE.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); for (int plusP = 0; plusP < numofLineA.Length; plusP++) { range = worksheet.Cells["A" + (addressY + plusP)]; range.Value = numofLineA[plusP]; } for (int plusP = 0; plusP < numofLineB.Length; plusP++) { range = worksheet.Cells["B" + (addressY + plusP)]; range.Value = numofLineB[plusP]; } for (int plusP = 0; plusP < numofLineC.Length; plusP++) { range = worksheet.Cells["C" + (addressY + plusP)]; range.Value = numofLineC[plusP]; } for (int plusP = 0; plusP < numofLineD.Length; plusP++) { range = worksheet.Cells["D" + (addressY + plusP)]; range.Value = numofLineD[plusP]; } for (int plusP = 0; plusP < numofLineE.Length; plusP++) { range = worksheet.Cells["E" + (addressY + plusP)]; range.Value = numofLineE[plusP]; } plus = Math.Max(numofLineA.Length, numofLineB.Length); plus = Math.Max(numofLineC.Length, plus); plus = Math.Max(numofLineD.Length, plus); plus = Math.Max(numofLineE.Length, plus); addressY = addressY + plus - 1; } string outPath = ""; Common.SaveExcelTemplate(workbook, "N4文法", "xls", out outPath); if (File.Exists(outPath)) { System.Diagnostics.Process.Start(outPath); } } catch (Exception) { throw; } finally { workbook.Close(); } }
private void OutPutExcel_2000共通単語(DataTable adtData) { string templatePath = Common.GetTemplate("2000共通単語_テンプレート.xls"); SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(templatePath); try { SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets["2000共通単語"]; SpreadsheetGear.IRange range = null; for (int i = 0, addressY = 2; i < adtData.Rows.Count; i++, addressY++) { range = worksheet.Cells["A" + addressY]; range.Value = adtData.Rows[i]["id"]; range = worksheet.Cells["B" + addressY]; range.Value = adtData.Rows[i]["jp"]; if (adtData.Rows[i]["read"].ToString().Length > 0 || adtData.Rows[i]["tooltipText"].ToString().Length > 0) { range.AddComment(adtData.Rows[i]["read"].ToString().Length > 0 ? (adtData.Rows[i]["read"].ToString() + Environment.NewLine + adtData.Rows[i]["tooltipText"].ToString()) : adtData.Rows[i]["tooltipText"].ToString()); SpreadsheetGear.IComment icomment = range.Comment; using (Graphics g = this.CreateGraphics()) { string item = icomment.ToString(); SizeF sizeF = g.MeasureString(item, Font); icomment.Shape.Width = sizeF.Width; icomment.Shape.Height = sizeF.Height; } } range = worksheet.Cells["C" + addressY]; range.Value = adtData.Rows[i]["read"]; range.WrapText = false; range = worksheet.Cells["D" + addressY]; range.Value = adtData.Rows[i]["vi"]; range.WrapText = false; range = worksheet.Cells["E" + addressY]; range.Value = adtData.Rows[i]["innerText"]; range.WrapText = false; range = worksheet.Cells["F" + addressY]; range.Value = adtData.Rows[i]["outerHtml"]; range.WrapText = false; range = worksheet.Cells["G" + addressY]; range.Value = adtData.Rows[i]["tooltipText"]; range.WrapText = false; } string outPath = ""; Common.SaveExcelTemplate(workbook, "2000共通単語", "xls", out outPath); if (File.Exists(outPath)) { System.Diagnostics.Process.Start(outPath); } } catch (Exception) { throw; } finally { workbook.Close(); } }