hai all,
i want to set width, alignment for excell sheet columns programatically through c#,
how to do this?
my coding -
public void exportToExcel(DataGridView myGrid, string strHiddenCols,string strHeading)
-
{
-
string[] strArrSplitCols;
-
try
-
{
-
strArrSplitCols = strHiddenCols.Split('^');
-
if (strHiddenCols.Trim() != "")
-
{
-
for (int intLoop = 0; intLoop < strArrSplitCols.Length; intLoop++)
-
{
-
myGrid.Columns[Convert.ToInt32(strArrSplitCols[intLoop])].Visible = false;
-
}
-
}
-
myGrid.SelectAll();
-
if (myGrid.Columns.Count != strHiddenCols.Length-1)
-
{
-
Clipboard.SetDataObject(myGrid.GetClipboardContent(), false);
-
ApplicationClass ExcelApp;
-
ExcelApp = new ApplicationClass();
-
ExcelApp.Application.Workbooks.Add(true);
-
ExcelApp.Visible = true;
-
Worksheet ws = new Worksheet();
-
ws = (Worksheet)ExcelApp.ActiveSheet;
-
int colCount = 0;
-
string[] strArrCompany;
-
string strCompanyDtls = iSQL.retrieveRecords("header,telephone,fax,email,website", "company", "company_id=1");
-
strCompanyDtls = strCompanyDtls.Substring(0, strCompanyDtls.Length - 1);
-
strArrCompany = strCompanyDtls.Split('^');
-
ExcelApp.Cells[1, 2] = "Company : " + strArrCompany[0];
-
ExcelApp.Cells[1, 4] = "Phone : " + strArrCompany[1];
-
ExcelApp.Cells[1, 6] = "Fax : " + strArrCompany[2];
-
ExcelApp.Cells[1, 8] = "Email : " + strArrCompany[3];
-
ExcelApp.Cells[1, 10] = "Website : " + strArrCompany[4];
-
ExcelApp.Cells[3, 2] = "Employee : " + General.EMPLOYEE_NAME;
-
ExcelApp.Cells[5, 6] = strHeading;
-
for (int intLoop = 0; intLoop < myGrid.ColumnCount; intLoop++)
-
{
-
if (myGrid.Columns[intLoop].Visible)
-
{
-
ExcelApp.Cells[7, colCount + 2] = myGrid.Columns[intLoop].HeaderText;
-
ExcelApp.Cells.Font.Bold = true;
-
colCount += 1;
-
}
-
}
-
-
ws.Paste(ws.Cells[9, 1], Clipboard.GetText());
-
if (strHiddenCols.Trim() != "")
-
{
-
for (int intLoop = 0; intLoop < strArrSplitCols.Length; intLoop++)
-
{
-
myGrid.Columns[Convert.ToInt32(strArrSplitCols[intLoop])].Visible = true;
-
}
-
}
-
}
-
else
-
{
-
if (strHiddenCols.Trim() != "")
-
{
-
for (int intLoop = 0; intLoop < strArrSplitCols.Length; intLoop++)
-
{
-
myGrid.Columns[Convert.ToInt32(strArrSplitCols[intLoop])].Visible = true;
-
}
-
}
-
}
-
-
-
}
-
catch (Exception ex)
-
{
-
General.writeErrorLog("ExcelExport", "exportToExcel", ex.Message);
-
}
-
}
-
1 1458
The ColumnWidth property may work for you. HTH.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Niyazi |
last post by:
Hi,
I have to retrieve a data from AS400 DB2 and after working with data I have
to export into one of existing Excel file.
I can connect into specific library in AS400 DB2 using AS400...
|
by: Mustafa |
last post by:
I have an ASP script where i am generating the excell sheet dynamically i am
passing some column header text which is long text so i want it to display
it vertically in column (cell).In excell i...
|
by: Mustafa |
last post by:
I have an ASP script where i am generating the excell sheet dynamically i am
passing text as column heading which is long text so i want it to display it
vertically in column (cell).In excell i...
|
by: nivas.meda |
last post by:
Hi,
I have an excel sheet with a graph and cells.If i change the value in
the excel cells the graph will reflect.Now i am going to implement this
functionality in html page.I successfully saved...
|
by: Hi5 |
last post by:
Hi,
I have designed a databasewhich is now able to store all data from my
client's Excel sheet.Now I am looking for a good way to move their data
into this Db.
If I want to do this myself will...
| |
by: seshu |
last post by:
hi every body
This is seshu i have doubt in mysql i have some date in excell sheet to export that data i have copied all the data into a text file and the wrote this code in...
|
by: glibo |
last post by:
I am trying to change the tab name when i open a excell spread sheet on the run time in c#.
I changed it in the code:
Response.AddHeader("content-disposition","filename=" + sFileName + ".xls");...
|
by: Ali Rizwan |
last post by:
Hi all,
I m creating a database. The data for database will fetched from an excell sheet. Now how can i read an excell sheet and update my database with that excell sheet.
Or
I want to show...
|
by: ashokd001 |
last post by:
Hi,
How do i read time field from excell sheet by python.
I am getting "0.400694444444" value but sheet has "9:37:00 AM" .
How to convert it ?
Regards,
Ashok
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |