Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8417183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:58:13+00:00 2026-06-10T01:58:13+00:00

I have an Excel File which serves as a template for my Excel work

  • 0

I have an Excel File which serves as a template for my Excel work and I want to programatically fill this template with data.

When I create a row and an accompanying cell and set a border for the newly created cell, the whole sheet is assigned this border. Naturally, I only want the single cell to have that border. Here is the code:

string path = Application.StartupPath + "\\" + "Excels\\myTemplate.xls";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs, true);
HSSFSheet sheet = templateWorkbook.GetSheet("sheet2");

int rowIndex = 3;
var row = sheet.CreateRow(rowIndex);

int i = 0;
string zoneNo;
string SubsidiaryCode = string.Empty;
foreach (DataRow r in dtBill.Rows)
{
  SubsidiaryCode = (r["SubsidiaryCode"].ToString().Trim());
  zoneNo = (r["ZoneNO"].ToString().Trim());

  HSSFCell cell = (HSSFCell)row.CreateCell(i);
  cell.SetCellValue("Zone " + zoneNo + "-code :" + SubsidiaryCode);
  cell.CellStyle.BorderBottom = HSSFCellStyle.BORDER_MEDIUM;
  i++;

  row.CreateCell(i).SetCellValue(r["Date"].ToString().Trim());
  row.CreateCell(i).CellStyle.BorderBottom = HSSFCellStyle.BORDER_MEDIUM;
  i++;

  rowIndex++;
  row = sheet.CreateRow(rowIndex);
  i = 0;
}

sheet.ForceFormulaRecalculation = true;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:58:15+00:00Added an answer on June 10, 2026 at 1:58 am

    I found the answer

    var row = sheet.CreateRow(rowGlobal);
    
    
    HSSFCellStyle style1 = templateWorkbook.CreateCellStyle();
            style1.BorderRight = HSSFCellStyle.BORDER_MEDIUM;
            style1.BorderBottom = HSSFCellStyle.BORDER_MEDIUM;
            style1.Alignment = HSSFCellStyle.ALIGN_CENTER;
            //style1.FillPattern = HSSFCellStyle.SOLID_FOREGROUND;
            //style1.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.GREEN.index;
            HSSFFont font1 = templateWorkbook.CreateFont();
            //font1.Color = NPOI.HSSF.Util.HSSFColor.BROWN.index;
            font1.FontName = "B Nazanin";
            style1.SetFont(font1);
    
    cell = row.CreateCell(2);
               cell.SetCellValue(0);
               cell.CellStyle = style1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this excel file which I have been able to write the data
I have an excel file which is refreshing data every few seconds and running
I have few text and excel file, from which I need to import data
I have an excel file and I want to read each column and create
I need help in this matter: We have a template of Excel file in
I have an Excel worksheet where the user enters certain data, which I want
I have an SSIS package which reads an Excel File (Data Flow Source) and
I have a SSIS package which reads an Excel File (Data Flow Source) and
I have a small SSIS package which exports data to a excel file from
I have a excel file which is as follows . 1 Kr Veerappan 123

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.