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

  • Home
  • SEARCH
  • 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 8641585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:33:48+00:00 2026-06-12T11:33:48+00:00

I needs to create shipping lable based on the excel template at run time

  • 0

I needs to create shipping lable based on the excel template at run time using the c#.

Right now I have working system, where I am replacing the fields name in excel template with database value and sending it for printing.

But It is creating space if value is null in database. I don’t want that space.
In a single excel row, there are more than 2 cells needs to be replaced so if value is not present then I needs to delete the cell only(as I can’t delete row) and shift its just below cell to that position or merge it with below cell.

If you have any better way to generate shipping lable based on excel template then let me know that.Thanks

                Excel.Application xlApp;
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;
            xlApp = new Excel.ApplicationClass();

            //string path = AppDomain.CurrentDomain.BaseDirectory + @printLabelName;
            string fileLocation = "";
            DataTable dtPath = clsData.getFileLocations();
            if (dtPath.Rows.Count != 0)
            {
                //ctbExport.Text = dt.Rows[0]["exportFileLocation"].ToString();
                fileLocation = dtPath.Rows[0]["printTemplateLocation"].ToString() + "\\";
            }

            String[] orderList = ctbOrderNo.Text.Split(' ');
            for (int i = 0; i < orderList.LongLength; i++)
            {
                string strOrderNo = orderList[i];

                int val = clsData.updOrderDataBulkPrint(Convert.ToDecimal(ctbCustomValue.Text), cmbCustomType.Text, strOrderNo);

                DataTable dt = clsData.getOrderDetailByOrderNo(strOrderNo);
                if (dt.Rows.Count == 0)
                {
                    MessageBox.Show("Order No. " + strOrderNo + " doesn't exist");
                    return;
                }
                DataTable dtSender = clsData.getSenderDataById(Convert.ToInt32(cmbSender.SelectedValue));
                if (dtSender.Rows.Count > 0 && dt.Rows.Count > 0)
                {
                    //We will name shipping label excel template file names as number for e.g. 1 , 2 , 3 , 4 , 4 etc. 
                    //user will put of these values and then system will know which shipping label excel template to use for all these orders.
                    string printLabelName = numUpDownPrintLabelRype.Value.ToString() + ".xlsx";

                    //string path = AppDomain.CurrentDomain.BaseDirectory + @printLabelName;                       
                    string path = fileLocation + @printLabelName;

                    bool isPathCorrect = true;
                    try
                    {
                        object missingValue = Type.Missing;

                        xlWorkBook = xlApp.Workbooks.Open(path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                        //MessageBox.Show(xlWorkSheet.get_Range("A1", "A1").Value2.ToString());                                           
                        xlWorkSheet.Cells.Replace("SenderName", dtSender.Rows[0]["senderName"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("SenderCompanyName", dtSender.Rows[0]["senderCompanyName"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("SenderAdressLine1", dtSender.Rows[0]["senderAdressLine1"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("SenderAddressLine2", dtSender.Rows[0]["senderAddressLine2"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("SenderCity", dtSender.Rows[0]["senderCity"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("SenderState", dtSender.Rows[0]["senderState"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("SenderZIP", dtSender.Rows[0]["senderZIP"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("SenderCountry", dtSender.Rows[0]["senderCountry"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("OrderNumber", dt.Rows[0]["orderNo"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("Zone", dt.Rows[0]["zone"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);

                        xlWorkSheet.Cells.Replace("CustomerName", dt.Rows[0]["customerName"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);

                        xlWorkSheet.Cells.Replace("CustomerCompanyName", dt.Rows[0]["cCompanyName"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);

                        object misval = Type.Missing;



                      //Replace values by database values here


                        xlWorkSheet.Cells.Replace("CustomerAddressLine1", dt.Rows[0]["cAddressLine1"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("CustomerAddressLine2", dt.Rows[0]["cAddressLine2"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("CustomerAddressLine3", dt.Rows[0]["cAddressLine3"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("CustomerAddressCity", dt.Rows[0]["cAddressCity"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("CustomerAddressState", dt.Rows[0]["cAddressState"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("CustomerAddressZIP", dt.Rows[0]["cAddressZIP"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("CustomerAddressCountry", dt.Rows[0]["cAddressCountry"].ToString(), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);

                        xlWorkSheet.Cells.Replace("ProductType", cmbProdType.Text, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("CustomsType", cmbCustomType.Text, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
                        xlWorkSheet.Cells.Replace("CustomsValue", ctbCustomValue.Text, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);

                        xlWorkBook.PrintOut(1, 1, 1, false, misValue, misValue, misValue, misValue);

                        xlWorkBook.Close(false, misValue, misValue);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Can't open Label Template, please check location.");
                        isPathCorrect = false;
                    }
                }
                else {
                    MessageBox.Show("This Sender doesn't exist.");
                }
            }
            xlApp.Quit();
  • 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-12T11:33:50+00:00Added an answer on June 12, 2026 at 11:33 am

    so if value is not present then I needs to delete the cell only(as I can’t delete row) and shift its just below cell to that position or merge it with below cell

    You want to use the .Range.Delete(Shift) method that is given in the Excel PIA DLLs (the interop DLLs which I’m sure you’re already using).

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.delete(v=office.11).aspx

    xlDeleteShiftDirection

    Once you find the cell that you want to delete, use something like this (which part of was lifted from your code example):

    UNTESTED

    xlWorkSheet.get_Range("A1", "A1").Delete(XlDeleteShiftDirection.xlShiftUp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a loop which needs to create an unspecified and indefinite amount of
I'm working on a Python script that needs to create about 50 distinct temporary
i would like to create an application that needs to have the option to
I'm looking to create a system where users specify shipping prices for their items.
I am trying to make a simple that needs to create an NSImage and
First of all, it needs to create some codes that handle any error in
I create a json that needs to be posted in jersey, a server running
I'm going to create widget which needs to update its content every minute (it
I'm trying to create a plugin which needs to read some data from a
I need to create an interface where a user needs to select how many

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.