PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label width. Show all posts
Showing posts with label width. Show all posts

Wednesday, October 5, 2022

[FIXED] How to PHPExcel set auto-columns width

 October 05, 2022     autosize, php, phpexcel, width     No comments   

Issue

I'm working with PHPExcel to export data for download. When open downloaded files, with cells have big number, it show "#######" instead of value number. I'm tried setAutoSize() for every columns then call $sheet->calculateColumnWidths() but it still not changes. I see calculateColumnWidths() at here, @Mark Baker says "calculateColumnWidths() increase the value by perhaps 5% to try and ensure that the entire column fits". If number length in cell exceed 5%, it seems doen's resolved the problem

UPDATE This is my function to auto size columns:

   function autoFitColumnWidthToContent($sheet, $fromCol, $toCol) {
        if (empty($toCol) ) {//not defined the last column, set it the max one
            $toCol = $sheet->getColumnDimension($sheet->getHighestColumn())->getColumnIndex();
        }
        for($i = $fromCol; $i <= $toCol; $i++) {
            $sheet->getColumnDimension($i)->setAutoSize(true);
        }
        $sheet->calculateColumnWidths();
    }

Solution

First potential problem may be that you're working with column letters. PHP's incrementor operation will work with column letters, so if $i is 'A', then $i++ will give 'B', and if $i is 'Z' than $i++ will give 'AA'; but you can't use <= as your comparator, as 'AA' is <= 'Z' when executed as a straight comparison.

Instead of

for($i = $fromCol; $i <= $toCol; $i++) {

use

$toCol++;
for($i = $fromCol; $i !== $toCol; $i++) {

To add the 5% margin after calling $sheet->calculateColumnWidths() do:

for($i = $fromCol; $i !== $toCol; $i++) {
    $calculatedWidth = $sheet->getColumnDimension($i)->getWidth();
    $sheet->getColumnDimension($i)->setWidth((int) $calculatedWidth * 1.05);
}


Answered By - Mark Baker
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, September 18, 2022

[FIXED] How to print F32 with 1 dec place and a fixed width in rust

 September 18, 2022     formatting, printing, rust, width     No comments   

Issue

Trying to replicate the following C printf invocation

printf("%6.1f %6.1f %6.1f\n", x, y, z);

in rust and I can't find it in the docs. I need 6 positions wide with 1 decimal place.

First time I've been stumped finding what I need there.


Solution

Formatting strings are documented in the documentation for std::fmt.

The equivalent of %6.1f would be {:6.1}:

println!("{:6.1} {:6.1} {:6.1}", x, y, z);

Playground



Answered By - harmic
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, August 11, 2022

[FIXED] Why use long decimal point values in CSS percentage widths?

 August 11, 2022     css, decimal, fluid, responsive-design, width     No comments   

Issue

I've noticed in my own work that 3 fluid columns fill out their parent element much better when their widths are set to 33.333% as opposed to just 33%. I've also noticed when researching various CSS frameworks (i.e. bootstrap.css) that they have 14 decimal places specified on their column widths! That seems like it would be either excessive or clever... but I don't know which.

So what is the value/benefit of having so many decimal places? From what I have gathered, there is an open debate on whether you should avoid decimal places or take advantage of them and I want to know if this should be of interest to me or to just not worry about it.


Solution

It is required in some cases. I'm working on a site using the Twitter Bootstrap which has 6 divs stretching the full width of the site. If I just make the width of each one 16.66% a noticeable gap is left at the end, if I make the width 16.67% one of the divs is pushed onto the line below. This meant to get the divs to fill the full space, I had to set the width to 16.6667% which works perfectly in Chrome and Firefox but it seems that Safari and IE round the decimal point down to 2 places so I'm left with a gap when using them. So sometimes it might seem excessive but other times it is actually needed.

Dave



Answered By - Dave Marshall
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, August 2, 2022

[FIXED] How to set up fixed width for <td>?

 August 02, 2022     css, html-table, twitter-bootstrap, width     No comments   

Issue

Simple scheme:

  <tr class="something">
    <td>A</td>
    <td>B</td>
    <td>C</td>
    <td>D</td>
  </tr>

I need to set up a fixed width for <td>. I've tried:

tr.something {
  td {
    width: 90px;
  }
}

Also

td.something {
  width: 90px;
}

for

<td class="something">B</td>

And even

<td style="width: 90px;">B</td>

But the width of <td> is still the same.


Solution

For Bootstrap 4.0:

In Bootstrap 4.0.0 you cannot use the col-* classes reliably (works in Firefox, but not in Chrome). You need to use OhadR's answer:

<tr>
  <th style="width: 16.66%">Col 1</th>
  <th style="width: 25%">Col 2</th>
  <th style="width: 50%">Col 4</th>
  <th style="width:  8.33%">Col 5</th>
</tr>

For Bootstrap 3.0:

With twitter bootstrap 3 use: class="col-md-*" where * is a number of columns of width.

<tr class="something">
    <td class="col-md-2">A</td>
    <td class="col-md-3">B</td>
    <td class="col-md-6">C</td>
    <td class="col-md-1">D</td>
</tr>

For Bootstrap 2.0:

With twitter bootstrap 2 use: class="span*" where * is a number of columns of width.

<tr class="something">
    <td class="span2">A</td>
    <td class="span3">B</td>
    <td class="span6">C</td>
    <td class="span1">D</td>
</tr>

** If you have <th> elements set the width there and not on the <td> elements.



Answered By - Paulo
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, July 29, 2022

[FIXED] How to make this page responsive for all resolutions?

 July 29, 2022     css, html, image, twitter-bootstrap, width     No comments   

Issue

I'm new and I'm having a problem--this page is not responsive for 1366, and 1280 resolutions on PC, on 1920, and on mobile it's perfect. May you please help me with this one?

I tried adding contain on object-fit, but that didn't help me, I think the problem is with the width but I can't figure out how to solve this properly without ruining it on 1920 resolution and mobile phone.

Resolution 1366

enter image description here

.container1 {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
}

.container1>div {
  padding: 0px 5px;
  max-width: 100%;
  height: 325px;
}

.container1 div img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.zgrade {
  position: relative;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  overflow: hidden;
  max-width: 745px;
  min-width: 428px;
}

.zgradeimg {
  width: 500px;
  -moz-transition: all 0.3s ease-in-out;
  -webkit-transition: all 0.3s ease-in-out;
  transition: all 0.4s ease-in-out;
}

.zgrade:hover img {
  -moz-transform: scale(1.1);
  -webkit-transform: scale(1.1);
  transform: scale(1.1);
}

@media screen and (max-width: 780px) {
  .container1 {
    flex-direction: column;
  }
  .container1>div {
    padding: 10px 5px;
  }
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<div class="container1">
  <div class="row justify-content-center">
    <div class="zgrade">
      <a href="zgradaA.html">
        <img src="https://via.placeholder.com/800" /></a>
    </div>

    <br>
    <div class="zgrade"><img src="https://via.placeholder.com/800" />
    </div>
  </div>
</div>

<div class="p-6"></div>

<div class="container1">
  <div class="row justify-content-center ">
    <div class="zgrade ">
      <img src="https://via.placeholder.com/800" /></div>
    <br>

    <div class="zgrade"><img src="assets/img/szgrade/zgradaD.jpg" />
    </div>
  </div>
</div>


Solution

I removed Row code from the container and it's working. :) They are only used for containing columns. I don't have columns so I tried removing the row class and everything is cool right now. I hope that this will stay like this :)



Answered By - the nr
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing