本文介绍了我怎么可以大胆在Excel工作表使用C#特定的行或单元格的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我出口从List<数据;>创先争优。我想提出一些具体的行和单元格大胆。我需要做一些细胞也合并。
I am exporting data from a List<> to excel. I want to make some specific rows and cells bold. I need to make some cell merged also.
下面是我使用的代码。
Below is the code I am using.
try
{
Excel.Application application;
Excel.Workbook workBook;
Excel.Worksheet workSheet;
object misValue = System.Reflection.Missing.Value;
application = new Excel.ApplicationClass();
workBook = application.Workbooks.Add(misValue);
workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(1);
int i = 1;
workSheet.Cells[i, 2] = "MSS Close Sheet";
i++;
workSheet.Cells[i, 2] = "MSS - " + dpsNoTextBox.Text;
i++;
workSheet.Cells[i, 2] = customerNameTextBox.Text;
i++;
workSheet.Cells[i, 2] = "Opening Date : ";
workSheet.Cells[i, 3] = openingDateTextBox.Value.ToShortDateString();
i++;
workSheet.Cells[i, 2] = "Closing Date : ";
workSheet.Cells[i, 3] = closingDateTextBox.Value.ToShortDateString();
i++;
i++;
i++;
workSheet.Cells[i, 1] = "SL. No";
workSheet.Cells[i, 2] = "Month";
workSheet.Cells[i, 3] = "Amount Deposited";
workSheet.Cells[i, 4] = "Fine";
workSheet.Cells[i, 5] = "Cumulative Total";
workSheet.Cells[i, 6] = "Profit + Cumulative Total";
workSheet.Cells[i, 7] = "Profit @ " + profitRateComboBox.Text;
i++;
/////////////////////////////////////////////////////////
foreach (RecurringDeposit rd in RecurringDepositList)
{
workSheet.Cells[i, 1] = rd.SN.ToString();
workSheet.Cells[i, 2] = rd.MonthYear;
workSheet.Cells[i, 3] = rd.InstallmentSize.ToString();
workSheet.Cells[i, 4] = "";
workSheet.Cells[i, 5] = rd.CumulativeTotal.ToString();
workSheet.Cells[i, 6] = rd.ProfitCumulative.ToString();
workSheet.Cells[i, 7] = rd.Profit.ToString();
i++;
}
//////////////////////////////////////////////////////
////////////////////////////////////////////////////////
workSheet.Cells[i, 2] = "Total (" + RecurringDepositList.Count + " months installment)";
workSheet.Cells[i, 3] = totalAmountDepositedTextBox.Value.ToString("0.00");
i++;
workSheet.Cells[i, 2] = "a) Total Amount Deposited";
workSheet.Cells[i, 3] = totalAmountDepositedTextBox.Value.ToString("0.00");
i++;
workSheet.Cells[i, 2] = "b) Fine";
workSheet.Cells[i, 3] = "";
i++;
workSheet.Cells[i, 2] = "c) Total Pft Paid";
workSheet.Cells[i, 3] = totalProfitPaidTextBox.Value.ToString("0.00");
i++;
workSheet.Cells[i, 2] = "Sub Total";
workSheet.Cells[i, 3] = (totalAmountDepositedTextBox.Value + totalProfitPaidTextBox.Value).ToString("0.00");
i++;
workSheet.Cells[i, 2] = "Deduction";
i++;
workSheet.Cells[i, 2] = "a) Excise Duty";
workSheet.Cells[i, 3] = "0";
i++;
workSheet.Cells[i, 2] = "b) Income Tax on Pft. @ " + incomeTaxPercentageTextBox.Text;
workSheet.Cells[i, 3] = "0";
i++;
workSheet.Cells[i, 2] = "c) Account Closing Charge ";
workSheet.Cells[i, 3] = closingChargeCommaNumberTextBox.Value.ToString("0.00");
i++;
workSheet.Cells[i, 2] = "d) Outstanding on BAIM(FO) ";
workSheet.Cells[i, 3] = baimFOLowerTextBox.Value.ToString("0.00");
i++;
workSheet.Cells[i, 2] = "Total Deduction ";
workSheet.Cells[i, 3] = (incomeTaxDeductionTextBox.Value + closingChargeCommaNumberTextBox.Value + baimFOTextBox.Value).ToString("0.00");
i++;
workSheet.Cells[i, 2] = "Client Paid ";
workSheet.Cells[i, 3] = customerPayableNumberTextBox.Value.ToString("0.00");
i++;
workSheet.Cells[i, 2] = "e) Current Balance ";
workSheet.Cells[i, 3] = currentBalanceCommaNumberTextBox.Value.ToString("0.00");
workSheet.Cells[i, 5] = "Exp. Pft paid on MSS A/C(PL67054)";
workSheet.Cells[i, 6] = plTextBox.Value.ToString("0.00");
i++;
workSheet.Cells[i, 2] = "e) Total Paid ";
workSheet.Cells[i, 3] = customerPayableNumberTextBox.Value.ToString("0.00");
workSheet.Cells[i, 5] = "IT on Pft (BDT16216)";
workSheet.Cells[i, 6] = incomeTaxDeductionTextBox.Value.ToString("0.00");
i++;
workSheet.Cells[i, 2] = "Difference";
workSheet.Cells[i, 3] = (currentBalanceCommaNumberTextBox.Value - customerPayableNumberTextBox.Value).ToString("0.00");
workSheet.Cells[i, 5] = "Account Closing Charge";
workSheet.Cells[i, 6] = closingChargeCommaNumberTextBox.Value;
i++;
///////////////////////////////////////////////////////////////
workBook.SaveAs("D:\\" + dpsNoTextBox.Text.Trim() + "-" + customerNameTextBox.Text.Trim() + ".xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
workBook.Close(true, misValue, misValue);
application.Quit();
releaseObject(workSheet);
releaseObject(workBook);
releaseObject(application);
的
推荐答案
如何粗体整排10例如:
workSheet.Cells[10, 1].EntireRow.Font.Bold = true;
更正式的:
More formally:
Microsoft.Office.Interop.Excel.Range rng = workSheet.Cells[10, 1] as Xl.Range;
rng.EntireRow.Font.Bold = true;
如何粗体特定的细胞'A10',例如:
How to Bold Specific Cell 'A10' for example:
workSheet.Cells[10, 1].Font.Bold = true;
小比较正规的:
Little more formal:
int row = 1;
int column = 1; /// 1 = 'A' in Excel
Microsoft.Office.Interop.Excel.Range rng = workSheet.Cells[row, column] as Xl.Range;
rng.Font.Bold = true;
这篇关于我怎么可以大胆在Excel工作表使用C#特定的行或单元格的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!